Sullan Sullan - 3 months ago 7x
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


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