Sullan Sullan - 4 months ago 14
Javascript Question

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??

Answer

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();
Comments