Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  108] [ 2]  / answers: 1 / hits: 27840  / 12 Years ago, thu, march 15, 2012, 12:00:00

Possible Duplicate:

How can I get a specific parameter from location.search?






I have a url like the following.



http://localhost/xxx.php?tPath=&pid=37


I want to get the pid=37 but by its name because on time the url is like above and then when page refreshed then the url becomes like the following.



http://localhost/xxx.php?tPath=&action=xxx&pid=37&value=13&fname=aaaa&fone=4321122


So I want to get the pid=37. It might be a function to which I pass the pid as a parameter and it returns its value.



How will I do this?


More From » url

 Answers
71

Take a look at this or follow a solution like this:



function getParam( name )
{
name = name.replace(/[[]/,\[).replace(/[]]/,\]);
var regexS = [\?&]+name+=([^&#]*);
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return ;
else
return results[1];
}

var frank_param = getParam( 'pid' );

[#86829] Wednesday, March 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adrianobeds

Total Points: 558
Total Questions: 118
Total Answers: 116

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;