I am reading hidden field value using javascript. The value I am getting is within single quote( '78963' ). I can i remove this single quote ? I want the value without single quote( 78963 ). Please help me to solve the problem.
I am reading hidden field value using javascript. The value I am getting is within single quote( '78963' ). I can i remove this single quote ? I want the value without single quote( 78963 ). Please help me to solve the problem.
Share asked Mar 20, 2013 at 10:01 IrannabiIrannabi 1391 gold badge4 silver badges15 bronze badges 1-
1
Do you mean simply this:
yourValue.replace(/'/g, "");
? Or am I missing something? What are the possible values of the string? – James Allardice Commented Mar 20, 2013 at 10:03
5 Answers
Reset to default 5I guess you simply want to convert your string value to numeric.
Just use parseInt()
:
parseInt("78963", 10); // 78963
If the value pretends to be floating, there is parseFloat()
method:
parseFloat("78963.1"); // 78963.1
And one more shortcut to make casting:
+"78963"; // 78963
In case if you simply want to replace single quotes, you may use:
"'78963'".replace(/'/g, ""); // "78963"
(as stated by others) or do tricky split:
"'78963'".split("'")[1]; // "78963"
You can use .replace() function on strings: http://www.w3schools./jsref/jsref_replace.asp
str.substr(1, str.length - 2);
Just $('#element').val()
, you will get exact value. here element will be the id of hidden box.
If it's true that the value of the hidden input field contains single quotes, the (in my opinion) best answer is the one which JamesAllardice put in a ment:
yourValue.replace(/'/g, "");