Get value from a string after a special character
How do i trim and get the value after a special character from a hidden field The hidden field value is like this
Code
<input type=-"hidden" val="/TEST/Name?3"
How i get the value after the "question mark" symbol in jquery??
You can use .indexOf()
and .substr()
like this:
var val = $("input").val();
var myString = val.substr(val.indexOf("?") + 1)
You can test it out here. If you're sure of the format and there's only one question mark, you can just do this:
var myString = $("input").val().split("?").pop();
Assuming you have your hidden input in a jQuery object $myHidden
, you then use JavaScript (not jQuery) to get the part after ?
:
var myVal = $myHidden.val ();
var tmp = myVal.substr ( myVal.indexOf ( '?' ) + 1 ); // tmp now contains whatever is after ?