$("#index-link")[0].search = "?isNameChecked=False&isDateChecked=False&isStatusChecked=True"
How can I find the isStatusChecked == true
or false
from the above string using jQuery?
$("#index-link")[0].search = "?isNameChecked=False&isDateChecked=False&isStatusChecked=True"
How can I find the isStatusChecked == true
or false
from the above string using jQuery?
I guess there are several ways to do it.
One way is str.indexOf("isDateChecked=False")
which will return value > -1
if the string is found.
However regex might be a better option if you want to allow for variable spacing in the substrings you're checking for. For fixed strings though, I would avoid regex and go with indexof
you may need to look at substr function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr
or use search method http://www.w3schools.com/jsref/jsref_search.asp
Found a similar question to this that provided a function which does this here.
By modifying it a bit (assuming you want to use a string of text, not the url from the address bar) I came up with this -
function getParameterByName(name, url) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(url);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
Here's a fiddle with it in action - http://jsfiddle.net/dNe38/
The value is found by using a regular expression as Pranav suggested.
No jQuery required. Using built-in JavaScript functions:
var a = "?isNameChecked=False&isDateChecked=False&isStatusChecked=True";
var params = a.split("&");
params.forEach(function(param) {
var keyValue = param.split("=");
var key = keyValue[0];
var value = keyValue[1];
if(key === 'isStatusChecked') {
alert(value); //True
}
});
Works even if you add more parameters to it.
you can split if the string by isStatusChecked
var newString = asearch.split("isStatusChecked=").pop(-1);
Simple regexp will make a job:
var str = "?isNameChecked=False&isDateChecked=False&isStatusChecked=True";
str.match(/isStatusChecked=(.*?)(?:$|&)/); // ["isStatusChecked=True", "True"]