How do you split an html link with a javascript string?

thesatsui

New member
I have a defined function that will set a string as a zip code (via prompt). It eventually leads to a url that would look similar to this

cheese.com/zipcode=90210&lang=eng

How would I get that string involved in zipcode?

My current solution is:
<a href="cheese.com/zipcode="+zipcode+"&lang=eng">

Not sure if that's correct but I completely forgot how to do that.
 
Not clear what you want. If you want the string "90210" from the string "cheese.com/zipcode=90210&lang=eng" u may do the following :

var myString = "cheese.com/zipcode=90210&lang=eng";

var mySplitResult = myString.split("=");

var mySplitResult2 = mySplitResult[1].split("&");

alert(mySplitResult2[0]);

You would get your zipcode within this.

Hope this is what you wanted and it helps...................
 
Back
Top