...

View Full Version : Need to get a string from a url



whippet19027
03-10-2011, 06:03 PM
This is probably easy if I knew Javascript. Can someone show me the code to get the number "800014352" part from the url????

http://testebiz/ebizbtest/ShoppingCart/ACPOrderSummary/tabid/161/ORDERNUMBER/8000145352/Default.aspx

Philip M
03-10-2011, 06:42 PM
This is probably easy if I knew Javascript. Can someone show me the code to get the number "800014352" part from the url????

http://testebiz/ebizbtest/ShoppingCart/ACPOrderSummary/tabid/161/ORDERNUMBER/8000145352/Default.aspx

Which url are we talking about?

Is this what you mean?


var url ="http://www.codingforums.com/showthread.php?t=181928";
var num = url.replace(/[^0-9]/g,"")
alert (num);


Two legs on a stool are no better than one.

whippet19027
03-10-2011, 06:46 PM
The url below the post

http://testebiz/ebizbtest/ShoppingCart/ACPOrderSummary/tabid/161/ORDERNUMBER/8000145352/Default.aspx

whippet19027
03-10-2011, 06:47 PM
is the url now showing up???

whippet19027
03-10-2011, 06:49 PM
i mean is the url not showing up???

Philip M
03-10-2011, 06:51 PM
i mean is the url not showing up???

No. Appears to have a typo in it.

whippet19027
03-10-2011, 06:51 PM
this is what i mean

http://website/blah/181928/index.htm

i need to get at the number in the url

Krupski
03-10-2011, 07:00 PM
Which url are we talking about?

The link in the OP's URL is:


http://testebiz/ebizbtest/ShoppingCart/ACPOrderSummary/tabid/161/ORDERNUMBER/8000145352/Default.aspx

Maybe something like this:



var url = 'http://testebiz/ebizbtest/ShoppingCart/ACPOrderSummary/tabid/161/ORDERNUMBER/8000145352/Default.aspx';
var num = url.replace(/[\s\S]*ORDERNUMBER\/(.*?)\/[\s\S]*/gi,'$1');
alert('The extracted order number is ' + num);


I'm assuming that "/ORDERNUMBER/" will always be in the URL... the regex may need to be adjusted accordingly.

-- Roger

Krupski
03-10-2011, 07:01 PM
this is what i mean

http://website/blah/181928/index.htm

i need to get at the number in the url

Your links are dead. a LITTLE more help would.... um... help.

whippet19027
03-10-2011, 07:25 PM
These urls are behind a firewall.

Ok this is what I am trying to do. I am trying to get an order numbers from url's. Originally the urls had a parameter ?ORDERNUMBER=123456 but the vendor changed this and now the urls have the order number in the path of the url.

This is what I was using originally to get the order number

<script>
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}

}
</script>

Krupski what you did works I just dont know how to change the function to do what you did

whippet19027
03-10-2011, 07:57 PM
Figure it out. Thanks a lot for your help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum