|
|
Petskull
Maniac (V) Mad Scientist
From: 127 Halcyon Road, Marenia, Atlantis Insane since: Aug 2000
|
posted 12-17-2001 08:13
I want to make a page so that I can have something like:
www.peaceandlove.com/goodstuff.html?weight=24
...or something like that....
What I want to do is to URL encode a variable so I can use it with Javascript.
How can I know what the variable is from my script?
Is this even possible?
"A kleptomaniac is a person who helps himself because he can't help himself." --Henry Morgan
ICQ: 67751342
|
CPrompt
Maniac (V) Inmate
From: there...no..there..... Insane since: May 2001
|
posted 12-17-2001 17:00
I can't see anything there. When I went to www.peaceandlove.com I got the parent directory with nothing in it. I doubt that I could help but someone else may need to see the example before they can help.
Just wanted to let you know.
Later,
C:\
|
GRUMBLE
Paranoid (IV) Mad Scientist
From: Omicron Persei 8 Insane since: Oct 2000
|
posted 12-17-2001 17:58
afaik this is not possible with javascript. you'll need a server-side scripting language.
SSS: executed on server. portable variables to next page.
javascript: executed in browser. variables only available on one single page.
|
Allewyn
Maniac (V) Mad Scientist
From: Solitary confinement Insane since: Feb 2001
|
posted 12-17-2001 18:02
Yeah, no access to anything but ftp directory via browser
|
Petskull
Maniac (V) Mad Scientist
From: 127 Halcyon Road, Marenia, Atlantis Insane since: Aug 2000
|
posted 12-17-2001 18:45
actually, I didn't even know there WAS a www.peaceandlove.com ... I was just kidding
hehe
and I its ok if the variabl exists in onl that page, that's what I want....
think of it as a page which you call: www.cookforme.com/howdy.html?name=faloola
and returns a page that says something like:
Hello, faloola!!
know what I mean?
"A kleptomaniac is a person who helps himself because he can't help himself." --Henry Morgan
ICQ: 67751342
|
mr.maX
Maniac (V) Mad Scientist
From: Belgrade, Serbia Insane since: Sep 2000
|
posted 12-17-2001 20:09
Use location.search in JavaScript to determinate what is contained in query string (after ? sign)...
|
Dracusis
Maniac (V) Inmate
From: Brisbane, Australia Insane since: Apr 2001
|
posted 12-17-2001 23:04
Yep, like Max said.
However, given your example, that'll return with the value "weight=24" and not the variabul weight with a value of 24. You'll have to use some sort of pattern matching to split up more then one bit of info doing it that way.
I'm not sure if your could create a variabul named from that input, although I'm not sure if javascript supports variabul variabuls <- that's not a typo. However, if it does then it shouldn't be that hard.
The other option would be to use a serverside language to catch the variabules and phrase them into JS variabules. PHP could do that quite easialy by dropping in and out of PHP mode inside your JS when you created the variabules.
|
Petskull
Maniac (V) Mad Scientist
From: 127 Halcyon Road, Marenia, Atlantis Insane since: Aug 2000
|
posted 12-18-2001 17:04
I wrote this little snippet:
code:
<script type="text/javascript">
<!--
weight=location.search;
document.writeln(weight);
//-->
</script>
but it returns
?24
how can I get rid of that question mark?
there's gotta be some sort of command that you can type like makeEncode(weight) and it'll magically understand the input....
"A kleptomaniac is a person who helps himself because he can't help himself." --Henry Morgan
ICQ: 67751342
|
GRUMBLE
Paranoid (IV) Mad Scientist
From: Omicron Persei 8 Insane since: Oct 2000
|
posted 12-18-2001 18:16
if you just wanna cut away that question mark from the string, you can use the substring() function.
mystring=mystring.substring(1,mystring.length);
btw: this is not tested, just came into my mind this way...
|
Petskull
Maniac (V) Mad Scientist
From: 127 Halcyon Road, Marenia, Atlantis Insane since: Aug 2000
|
posted 12-19-2001 01:05
well.... I made it work, but isn't that kinda.... ugly? Ain't there a more *picks nose* elegant solution?
"A kleptomaniac is a person who helps himself because he can't help himself." --Henry Morgan
ICQ: 67751342
|
Slime
Lunatic (VI) Mad Scientist
From: Massachusetts, USA Insane since: Mar 2000
|
posted 12-19-2001 03:52
That's not really *that* ugly. At least not in my opinion. =)
More simply, I think you can just do
data = location.search.substr(1); // truncates the first character
This is really just the same thing Grumble just showed you, but reduced into less code.
Of course, you could always write your own function to take something like "?weight=24&this=that&a=b" and return an object with properties weight == 24, this == "that", and a == "b". Depends how much it's worth your time to do.
|
Pugzly
Paranoid (IV) Inmate
From: 127.0.0.1 Insane since: Apr 2000
|
posted 12-19-2001 05:23
Or you could just use PHP.
|
Petskull
Maniac (V) Mad Scientist
From: 127 Halcyon Road, Marenia, Atlantis Insane since: Aug 2000
|
posted 12-19-2001 16:22
um... let's not and say we did....
"A kleptomaniac is a person who helps himself because he can't help himself." --Henry Morgan
ICQ: 67751342
|
Petskull
Maniac (V) Mad Scientist
From: 127 Halcyon Road, Marenia, Atlantis Insane since: Aug 2000
|
posted 12-19-2001 18:38
well what do you know? Look at CNet go!
the url: http://download.cnet.com/downloads/0-10044-100-5935863.html?dlrs=y&tag=dlntl
code:
var argstr = location.search.substring(1, location.search.length);
var args = argstr.split('&');
that sems to be the ticket....
edit: doh! I just realized that that doesn't actually *assign* the variables, it just put them in the array....
is there such a thing as a hash (like in Perl) in Javascript?
"A kleptomaniac is a person who helps himself because he can't help himself." --Henry Morgan
ICQ: 67751342
[This message has been edited by Petskull (edited 12-19-2001).]
[This message has been edited by Petskull (edited 12-19-2001).]
|
mr.maX
Maniac (V) Mad Scientist
From: Belgrade, Serbia Insane since: Sep 2000
|
posted 12-19-2001 19:11
|