Click to See Complete Forum and Search --> : Number from URL split


IxxI
07-01-2003, 07:47 AM
I've got a url?number, and I've split it at the question mark leaving url and number separate. I've then shoved the number in a variable, but it seems to treat it as a string because when you add another number to it it shoves it on the end as opposed to adding it. Is there anyway to get it to treat it as a number??

IxxI

pyro
07-01-2003, 07:50 AM
This will turn a string into a number:

Number(varname)

IxxI
07-01-2003, 08:03 AM
Thanks for the quick reply Pyro, but it doesn't seem to work - I get the same problem - any suggestions?

IxxI

Charles
07-01-2003, 08:06 AM
You're doing something wrong. Pyro's method is correct:

<script type="text/javascript">
<!--
url = 'http://fee.fie-foe.fum?25';
alert (Number(url.split(/\?/)[1]) + 25);
// -->
</script>

pyro
07-01-2003, 08:07 AM
Perhaps it still includes the ? If you just use window.location.search, you will get ?number. Use window.location.search.substr(1), or as Charles suggested, just split the URL at the ?

IxxI
07-01-2003, 08:20 AM
Sorry, I was using number after I'd split. I'd got the number part of the url in a variable and then using number - thanks all.

IxxI