?
Solved

JS - URL parsing to extract a particular parameter value

Posted on 2010-01-12
4
Medium Priority
?
253 Views
Last Modified: 2013-11-08
I'm familiar in PHP, but not JS -
i have a page where its URL would end in the form:
.....php?p=456&jp=j&n=Ac

I need to extract the value for the $_GET['p']   variable.
Is this possible to do in JS?

the reason i need it in JS  is because it's in the header, ahead of the execution of PHP-generated  content.

thanks
0
Comment
Question by:willsherwood
  • 3
4 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 26298456
Hello willsherwood,

Check the gup function here : http://www.netlobo.com/url_query_string_javascript.html

Regards.
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 26298561
Work too :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	function displayP() {
		var url = "http://www.google.php?p=456&jp=j&n=Ac";
		alert( url.substring( url.indexOf("?")+2 ,url.indexOf("&", url.indexOf("?")+2) ) );
	}
</script>
</head>
<body onload="displayP();">
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:willsherwood
ID: 31676386
thank you!!!
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26298583
You're welcome! Thanks for the points!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question