?
Solved

Get URL string...

Posted on 2003-03-06
6
Medium Priority
?
1,533 Views
Last Modified: 2007-12-19
Using javascript, how can I pull the last 6 digits from a url...

http://www.asfdjklasfd.com/card.html?x=123456


and put it into a variable...

Thanks
0
Comment
Question by:rJonesX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 8082762
Try this:

<html>
<head>
<script>
var xPar="";
if(window.location.href.match(/x=(\d+)/i))
  xPar=RegExp.$1
alert(xPar)
</script>
</head>
</html>

0
 
LVL 5

Expert Comment

by:funke
ID: 8082872

var urlString = "http://www.asfdjklasfd.com/card.html?x=123456";
var urlLength = url.length;

var lastSixDigits = urlString.substring( urlLength - 6, 6 );
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 200 total points
ID: 8083072

function querystring(name)   // returns a named value from the querystring
{
     var tmp = unescape( location.search.substring(1) );
     var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");

     if ( i >= 0 )
     {
          tmp = tmp.substring( name.length+i+1 );
          i = tmp.indexOf("&");
          return( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
     }

     return("");
}


// and in this case, you can get the value of the x parameter like this:

alert( querystring("x") );
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Dword
ID: 8085765
try this?

<script language="javascript">
var address = window.top.location.href
address = address.substring(address.length-6,address.length)
</script>
0
 

Expert Comment

by:Dword
ID: 8085771
type wrongly use 6 instead of address.length

<script language="javascript">
var address = window.top.location.href
address = address.substring(address.length-6,6)
</script>
0
 

Author Comment

by:rJonesX
ID: 8186517
Thanks again to all of the posters who provided invaluable advice. I am awarding knightEknight because their comments went above and beyond the call of the question, providing me with a solution that would easily fit several future scenarios as well.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 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