Friday, December 28, 2018

jquery - Split last word value in JavaScript string




I have a URL string in JavaScript below ex-
URL-"/MyProject/Information/EmpDetails.aspx?userId=79874&countryId=875567"



Now, I need to do below 2 things




  1. Check whether the country exists in above url or not and there will be only one countryId in above url


  2. Get the countryId value means 875567.





Thanks Guys for such good response quickly .I got the solution most of the answers are correct.



One More Question Guys I have hyperlink so i am generating some activities when onmousedown event .but the issue is it fires even when i do right click only..but i want the event which fires only on clicking the hyperlink double click or right click and then click


Answer



You need to use a combination of indexOf() and substring()



var ind = url.indexOf("countryId");
if (ind != -1){
// value is index of countryid plus length (10)

var countryId = url.substring(ind+10);
}else{
//no countryid
}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...