Sullan Sullan - 1 year ago 87
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??

Answer Source

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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download