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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

manipulating a string

Status
Not open for further replies.

secretsquirrel

Programmer
Mar 22, 2001
202
GB
hi,

i've got a URL with parameters in a hidden field which looks something like...

/cgi-bin/blahblah/page.w?param1=1&param2=2

i need to chop off the first part of the URL, so i'm left with

?param1=1&param2=2

can anyone recommend a way to do this, please?

previously i've had to do this with a URL in the address bar and it works using

document.location.search.split("w");

but if i do something similar with my hidden field it seems to replace all the 'w's in the string with a comma instead!

thanks in advance,

ss...
 
You also mentioned that:
reviously i've had to do this with a URL in the address bar and it works using

document.location.search.split("w");

but if i do something similar with my hidden field it seems to replace all the 'w's in the string with a comma instead!

This is easily explained if you were to understand that the .split("w") causes the passed string (document.location) to be converted into an array... with each element of the array delimited by the letter "w" (in this case).

You were most likely then alerting the returned result. This calls the .toString() method of the array... which returns a string with each element of the array delimited by a comma.

Hope this at least identifies that what you observed was not unexpected.

Jeff
 
ok! i'm an idiot!

i've just discovered that the code i put above splits the string up and puts the bits in an array!

so the following seems to work...

Code:
var myArray = document.all.hiddenform.action.value.split(".w");
myParams = myArray[1];

thanks for your incredibly quick response though billyray!

ss...
 
Don't use document.all unless you want your pages to work ONLY on IE and not in any other browser.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top