Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grab Value from URL 1

Status
Not open for further replies.

dontpunchme

Programmer
Jul 29, 2002
20
US
Hi,

I am trying grab a value that appears in a URL string. I am trying to get the "add" that appears after the "Submit=".

The script I have below works when there are no extra parameters.

output: add

but once you add in the extras "&taco&pizza" it spits out this.

output: add&taco

Also if I add parameters before the "Submit=", the output gets worse.

<script language="JavaScript">
var str = "var theleft = str.indexOf("Submit=") + 6;
var theright = str.lastIndexOf("&");
var total = (str.substring(theleft, theright));
document.write("output: ",total);
</script>

I think I may be going about this the wrong way.

Thanks for any quidance.
 
You're almost there:

Code:
var str = "[URL unfurl="true"]http://www.blahblah.com?monkey&;Submit=add&taco&pizza";[/URL]
var tempStr = str.substr(str.indexOf("Submit=") + 7);
var total = tempStr.substr(0, tempStr.indexOf("&"));
alert("output: " + total);

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top