Sagewire Logo

Passing MULTIPLE values using URL string

20 Message(s) by 6 Author(s) originally posted in javascript programming


From: Richard Hijdra Date:   Saturday, September 29, 2007
NG,

I got the following issue;

Would like to transfer multiple values from a fill-in form to a second
page using string s in the URL.

Have got it worked out for one value allready;

On page with form (using ASP)
this script; http://www.rhi.nl/temp/contact.txt (view source)

I use the following;

Response.Redirect("bedankttr.htm?"+Trouwdd.Value+"");

Of course I can edit this to
Response.Redirect("bedankttr.htm?"+Trouwdd.Value+""+Naam.Value+"");

But can not make it work on destination page to pull out the second value
on another place.

On destination page (for example
http://www.rhi.nl/contact/bedankttr.htm?01-01-2008)
I have putted in;
<script type="text/JAVAscript">
<!--
newVar=location.search;
document .write(newVar.substr(1));
//-->

</script>

How do I distill the second value from the string?

Richard


From: timsamshuijzen Date:   Saturday, September 29, 2007
wrote in message :
How do I distill the second value from the string?



Brr, not a very nice strategy in my opinion, but if you feel you must
use this strategy, how about doing something like this:

Response.Redirect("bedankttr.htm?Trouwdd=" +
encodeURIComponent(Trouwdd.Value) +
"&Naam=" + encodeURIComponent(Naam.Value));

Then adjust the code in bedankttr.htm accordingly to extract (and
decode) the two values.


From: Safalra Date:   Saturday, September 29, 2007
wrote in message:
wrote in message:
How do I distill the second value from the string?
Brr, not a very nice strategy in my opinion, but if you feel you must
use this strategy, how about doing something like this:
Response.Redirect("bedankttr.htm?Trouwdd=" +
encodeURIComponent(Trouwdd.Value) +
"&Naam=" + encodeURIComponent(Naam.Value));
Then adjust the code in bedankttr.htm accordingly to extract (and
decode) the two values.Something like this will extract the query parameters into an convenient
structure:



http://www.safalra.com/programming /JAVAscript/get-data/

You can then use window.location.get.Trouwdd and window.location.get.Naam.--
Safalra (Stephen Morley)
http://www.safalra.com/


From: Richard Hijdra Date:   Sunday, September 30, 2007
Response.Redirect("bedankttr.htm?Trouwdd=" +
encodeURIComponent(Trouwdd.Value) +
"&Naam=" + encodeURIComponent(Naam.Value));


Is this for sending the data? That works, only distracting not...


Then adjust the code in bedankttr.htm accordingly to extract (and
decode) the two values.
http://www.safalra.com/programming/JAVAscript/get-data/
You can then use window.location.get.Trouwdd and window.location.get.Naam.



I have putted in
<script type="text/JAVAscript">
function initialiseGetData(){
window.location.get = new Object();
if (window.location.search && window.location.search.length > 1){
var getDataArray =
window.location.search.substr(1).replace('+', ' ').split (/[&;]/g);
for (var I = 0; i < getDataArray.length; i++){
var keyValuePair = getDataArray[i].split('=');
window.location.get[unescape(keyValuePair[0])]
= keyValuePair.length == 1
? ''
: unescape(keyValuePair[1]);
}
}
}
</script>


In the <HEAD> of the destination page

and

<!--
newVar=location.search;
document.write(window.location.get.Trouwdd);
//-->


in the <BODY> of it, but does not seem to work...

The string looks like
http://www.rhi.nl/contact/bedankttr.htm?Trouwdd=01-02-03&naam=Richard

Richard.


From: timsamshuijzen Date:   Sunday, September 30, 2007
I think you forgot to call initialiseGetData();

Change the code in the body to:

<!--
initialiseGetData();
document.write(window.location.get.Trouwdd);
//-->



From: Thomas PointedEars Lahn Date:   Sunday, September 30, 2007
wrote in message:
Something like this will extract the query parameters into an convenient
structure:
http://www.safalra.com/programming/JAVAscript/get-data/
You can then use window.location.get.Trouwdd and window.location.get.Naam.



It is well-known that host object s shouldn't be augmented as their
existence isn't guaranteed and their behavior for adding properties
isn't defined by the language standard. Therefore, using that code
is very unwise.PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee


From: Richard Hijdra Date:   Sunday, September 30, 2007
Well many thanks to you all (Tim, Stephen and Thomas)
Two things solved, got multiple values to second page, and spaces within
a value beeing transferred correctly.

One thing yet not solved, but maybe impossible;
Transferring the & caracter correctly (for instance transferring
'Richard Hijdra & Other partner') when this is filled in, only first
part comes thru (I understand why but'd still like it solved)

Greetz,
Richard Hijdra

wrote in message:

wrote in message:
Something like this will extract the query parameters into an convenient
structure:

http://www.safalra.com/programming/JAVAscript/get-data/

You can then use window.location.get.Trouwdd and window.location.get.Naam.
It is well-known that host objects shouldn't be augmented as their
existence isn't guaranteed and their behavior for adding properties
isn't defined by the language standard. Therefore, using that code
is very unwise.
PointedEars





From: Safalra Date:   Sunday, September 30, 2007
wrote in message:
wrote in message:
Something like this will extract the query parameters into an convenient
structure:

http://www.safalra.com/programming/JAVAscript/get-data/

You can then use window.location.get.Trouwdd and window.location.get.Naam.
It is well-known that host objects shouldn't be augmented as their
existence isn't guaranteed and their behavior for adding properties
isn't defined by the language standard. Therefore, using that code


> is very unwise.I have never heard of this 'well-known' problem before. If window.location
does not exist then any code attempting to access window.location.search
won't work anyway. Is there any current JAVAScript-capable browser in which
you can not add properties in this way (if there is then I will make the effort
to distinguish between the de facto and de jure standards)?--
Safalra (Stephen Morley)

Sortable Tables In JAVAScript:
http://www.safalra.com/web-design/JAVAscript/sortable-tables/


From: timsamshuijzen Date:   Sunday, September 30, 2007
Use the encodeURIComponent() function as previously described, so that
the request will be converted to for example:

http://www.rhi.nl/contact/bedankttr.htm?naam=Richard%20Hijdra%20%26%20Other%20partner

PS. Your bedankttr.htm page only needs to call the initialiseGetData()
function once, so you can remove the second call.


From: Thomas PointedEars Lahn Date:   Sunday, September 30, 2007
wrote in message:
wrote in message:
wrote in message:
Something like this will extract the query parameters into an
convenient structure:
http://www.safalra.com/programming/JAVAscript/get-data/
You can then use window.location.get.Trouwdd and
window.location.get.Naam.
It is well-known that host objects shouldn't be augmented as their
existence isn't guaranteed and their behavior for adding properties is
not defined by the language standard. Therefore, using that code is
very unwise.
I have never heard of this 'well-known' problem before.



Which means you aren't quite experienced enough. It has been discussed
here numerous times already.

If window.location does not exist then any code attempting to access
window.location.search won't work anyway.



That is true in *this* case.

Is there any current JAVAScript-capable browser in which you can not add
properties in this way (if there is then I will make the effort to
distinguish between the de facto and de jure standards)?



It real ly does not matter whether or not such a HTML UA (not only a browser)
can be named by anyone. Programming in a way that is specified to be
error -prone (see ES3, 8.6.2 §8) is irresponsible, incompetent Voodoo
programming. Especially because there is an easy way that makes the
error-prone approach unnecessary. For example:

http://PointedEars.de/scripts/search.jsPointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann


From: Richard Hijdra Date:   Sunday, September 30, 2007
Use the encodeURIComponent() function as previously described, so that
the request will be converted to for example:
http://www.rhi.nl/contact/bedankttr.htm?naam=Richard%20Hijdra%20%26%20Other%20partner
PS. Your bedankttr.htm page only needs to call the initialiseGetData()
function once, so you can remove the second call.



This

Response.Redirect("bedankttr.htm?trouwdd="+encodeURLComponent(Trouwdd.Value)+"&naam="+encodeURLComponent(Naam.Value));

Does not work (Runtime error)

While this one works
Response.Redirect("bedankttr.htm?trouwdd="+Trouwdd.Value+"&naam="+Naam.Value+"");

What exactly am I doing wrong?

Richard


From: timsamshuijzen Date:   Sunday, September 30, 2007
wrote in message:
Response.Redirect("bedankttr.htm?trouwdd=3D"+encodeURLComponent(Trouwdd.V=


alue=AD)+"&naam=3D"+encodeURLComponent(Naam.Value));
Does not work (Runtime error)
What exactly am I doing wrong?



You mistyped encodeURIComponent (You used an "L" instead of an "I")


From: Richard Hijdra Date:   Sunday, September 30, 2007
wrote in message:

wrote in message:
Response.Redirect("bedankttr.htm?trouwdd="+encodeURLComponent(Trouwdd.Value­)+"&naam="+encodeURLComponent(Naam.Value));

>Does not work (Runtime error)

What exactly am I doing wrong?

You mistyped encodeURIComponent (You used an "L" instead of an "I")


I've allready thought that'd be the problem (original post contained
URI) but does not work than either.

Richard


From: beegee Date:   Monday, October 01, 2007
On Sep 30, 10:59 am, Richard Hijdra <internetadre...@xxxxxxxxxxx>
wrote in message:
wrote in message:
wrote in message:
Response.Redirect("bedankttr.htm?trouwdd=3D"+encodeURLComponent(Trouwdd=


.Val=ADue=AD)+"&naam=3D"+encodeURLComponent(Naam.Value));
>>Does not work (Runtime error)
What exactly am I doing wrong?
> You mistyped encodeURIComponent (You used an "L" instead of an "I")
I have allready thought that'd be the problem (original post contained
URI) but does not work than either.
Richard



You could try encodeURIComponent(Trouwdd.Value + ""=AD=AD) to cast to
string. Are you the last guy in the world to be using server side
jscript?


From: Evertjan. Date:   Monday, October 01, 2007
wrote in message on 01 okt 2007 in comp.lang.JAVAscript:

Are you the last guy in the world to be using server side
jscript?



No, he isn't.

Serverside jscript is a joy for programmers.

The possiblility to port nearly the same code between serverside and
clientside is very useful.

The visually far nicer regex functions are too.

Intrinsic timezone and utc functions aren't available in vbscript.

Etc ....

Primarily it is a matter of taste.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


From: Thomas PointedEars Lahn Date:   Monday, October 01, 2007
wrote in message:
wrote in message:
wrote in message:
wrote in message:
Response.Redirect("bedankttr.htm?trouwdd="+encodeURLComponent(Trouwdd.Val­ue­)+"&naam="+encodeURLComponent(Naam.Value));
Does not work (Runtime error)
What exactly am I doing wrong?
You mistyped encodeURIComponent (You used an "L" instead of an "I")
I have allready thought that'd be the problem (original post contained
URI) but does not work than either.
You could try encodeURIComponent(Trouwdd.Value + ""­­) to cast to
string.



Unnecessary, because the method already does that. Specified and implemented.PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann


From: Safalra Date:   Saturday, October 06, 2007
wrote in message:
wrote in message:
wrote in message:
wrote in message:
Something like this will extract the query parameters into an
convenient structure:

http://www.safalra.com/programming/JAVAscript/get-data/

You can then use window.location.get.Trouwdd and
window.location.get.Naam.
It is well-known that host objects shouldn't be augmented as their
existence isn't guaranteed and their behavior for adding properties is
not defined by the language standard. Therefore, using that code is
very unwise.

I have never heard of this 'well-known' problem before.
Which means you aren't quite experienced enough.I will concede that.> It has been discussed here numerous times already.It might be an idea to add something on it to the FAQ, or somewhere else


where the vast majority of JAVAScript programmers who do not use Usenet will
read it. I have read numerous guides on common JAVAscript mistakes to avoid,
but this one was new to me. Is there any current JAVAScript-capable browser in which you can not add
properties in this way (if there is then I will make the effort to
distinguish between the de facto and de jure standards)?
It really does not matter whether or not such a HTML UA (not only a browser)
can be named by anyone. Programming in a way that is specified to be
error-prone (see ES3, 8.6.2 §8) is irresponsible, incompetent Voodoo
programming.I think that's unnecessarily harsh. Voodoo programming implies that the


code concerned should not really work but happens to do so for reasons only
a real expert could figure out. In contrast, in this case one'd
intuitively expect this to work and only a real expert who had read the
ECMAScript specification 'd know that in theory it could fail. Speaking
of which, the specification is very difficult to understand. I assume I have
misunderstood the following sentence, because it sounds very strange to me:

"Host objects may implement these methods in any manner unless specified
otherwise; for example, one possibility is that [[Get]] and [[Put]] for a
particular host object indeed fetch and store property values but
[[HasProperty]] always generates false."

Anyway, getting back on topic: I have rewritten the code to which you
objected. I suspect you still won't like it because as with much of my code
it makes use of ECMAScript Edition 3 feature s (splitting on regular
expressions and decodeURIComponent, for example) but I do not think it
contains anything that'd break in an awkward-yet-standards-compliant
browser.

--
Safalra (Stephen Morley)

Sortable Tables In JAVAScript:
http://www.safalra.com/web-design/JAVAscript/sortable-tables/


From: Thomas PointedEars Lahn Date:   Saturday, October 06, 2007
wrote in message:
wrote in message:
wrote in message:
wrote in message:
wrote in message:
Something like this will extract the query parameters into an
convenient structure:
http://www.safalra.com/programming/JAVAscript/get-data/
You can then use window.location.get.Trouwdd and
window.location.get.Naam.
It is well-known that host objects shouldn't be augmented as their
existence isn't guaranteed and their behavior for adding properties is
not defined by the language standard. Therefore, using that code is
very unwise.
I have never heard of this 'well-known' problem before.
[...]
It has been discussed here numerous times already.
It might be an idea to add something on it to the FAQ, [...]



Full ACK

Is there any current JAVAScript-capable browser in which you can not add
properties in this way (if there is then I will make the effort to
distinguish between the de facto and de jure standards)?
It really does not matter whether or not such a HTML UA (not only a browser)
can be named by anyone. Programming in a way that is specified to be
error-prone (see ES3, 8.6.2 §8) is irresponsible, incompetent Voodoo
programming.
I think that's unnecessarily harsh.



Well, I do not think so.

,-<http://en.wikipedia.org/wiki/Voodoo_programming>
|
| Voodoo programming (a term derived from 'voodoo economics') is a
| tongue-in-cheek term for using a programming device, system or language
| which one doesn't fully understand. The implication is that the end
| result shouldn't actually work, or even if it does work one doesn't
| understand why it works properly. [...]

Voodoo programming implies that the code concerned should not really work
but happens to do so for reasons only a real expert could figure out.



That is what I mean, for the most part. It should not really work because
host objects do not have to support augmentation (specified, and there are
known cases where this provision is implemented). Depending on the DOM
implementation, the attempt of augmentation can do anything from failing
silently to causing an error message. People who employ host object
augmentation nevertheless just do not know any better (which "doesn't fully
understand" applies to) or refuse to see the implications of their doing
(which "irresponsible" and "incompetent"'d apply to). However, one does
_not_ have to be an *expert* _not_ to do either one.

Anyway, getting back on topic: I have rewritten the code to which you
objected. I suspect you still won't like it because as with much of my code
it makes use of ECMAScript Edition 3 features (splitting on regular
expressions



That is implemented since JAVAScript 1.3 (NN4.0, 1997-06), and probably
since JScript 3.0 (MSHTML 4.0, 1997-10) which introduced RegExp support there.

and decodeURIComponent, for example)



That is implemented since JAVAScript 1.5 (Gecko 0.6, 2000-11), and JScript
5.5 (MSHTML 5.5, 2000-07).

Maybe <http://PointedEars.de/es-matrix>, which I am updating now, helps.

but I do not think it contains anything that'd break in an
awkward-yet-standards-compliant browser.



How did you get the impression that I'd generally object to code that
makes use of *standardized* features? I wouldn't.PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann


From: Safalra Date:   Sunday, October 07, 2007
wrote in message:
wrote in message:
Anyway, getting back on topic: I have rewritten the code to which you
objected. I suspect you still won't like it because as with much of my code
it makes use of ECMAScript Edition 3 features (splitting on regular
expressions
That is implemented since JAVAScript 1.3 (NN4.0, 1997-06), and probably
since JScript 3.0 (MSHTML 4.0, 1997-10) which introduced RegExp support there.
and decodeURIComponent, for example)
That is implemented since JAVAScript 1.5 (Gecko 0.6, 2000-11), and JScript
5.5 (MSHTML 5.5, 2000-07).
Maybe <http://PointedEars.de/es-matrix>, which I am updating now, helps.That looks very helpful. Generally I have been relying on the Mozilla


Developer Centre's JAVAScript reference guide to tell me the ECMAScript
versions and then if it's been an Edition 3 feature I have tested in old
versions of Internet Explorer just to make sure that that browser really
does support it. but I do not think it contains anything that'd break in an
awkward-yet-standards-compliant browser.
How did you get the impression that I'd generally object to code that
makes use of *standardized* features? I wouldn't.I thought you'd object because it does not fall back on older features


when the newer ones are not available - looking at your code, you seem very
concerned about supporting environments that, for example, might not even
support the split function (although maybe I have misunderstood what you're
doing, as your code does not seem to handle environments that implement the
split function but do not understand the form using regular expressions).--
Safalra (Stephen Morley)

Sortable Tables In JAVAScript:
http://www.safalra.com/web-design/JAVAscript/sortable-tables/


From: Thomas PointedEars Lahn Date:   Sunday, October 28, 2007
wrote in message:
wrote in message:
wrote in message:
but I do not think it contains anything that'd break in an
awkward-yet-standards-compliant browser.
How did you get the impression that I'd generally object to code
that makes use of *standardized* features? I wouldn't.
I thought you'd object because it does not fall back on older features
when the newer ones are not available - looking at your code, you seem
very concerned about supporting environments that, for example, might not
even support the split function



Please take note of the dates included. I started that library in another
decade; consequently, the code was written to support script engines of
another decade. For new code, I'd now draw the line at what Netscape
4.0 supports (see also [de] <

However, your observation is correct that in my code I try to provide for
fallbacks where there are some. They aren't only there for backwards
compatibility but also meant for educational purposes. (As my libraries are
mostly distributed as free software, anyone can use them in a modified form
that is more fitted to their needs, provided that the modification is
documented and that my original authorship is mentioned.)

(although maybe I have misunderstood what you're doing, as your code
does not seem to handle environments that implement the split function but
do not understand the form using regular expressions).



As you can see in the currently only slightly updated ECMAScript Support
Matrix, String.prototype.split() was introduced with JAVAScript 1.1 and
JScript 3.0 which are the exact versions RegExp support was introduced with.PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee



Next Message: Populate list box issue


Blogs related to Passing MULTIPLE values using URL string

I am experiencing a problem with flash ie that i cant seem to ...
is there a way to refresh a page via js. window.location=window.location ? would you mind take a look at my code and see if you have a quick suggestion on how I could pass that information? hm what was that' ? string value ...

*question* Take multiple results records based on a multiple ...
I don't get it, pdo_mysql isn't installed yet - I wouldn't be installing it. mtappenden, you should rather pass it as argument. And you can't access multidimentional arrays inside doublequoted string without using the "curly syntax". ...

i am passing an array from a page to a child page opened by it via ...
string i don't even know if those are concatable. because there the string usually has more buffer than really needed. so reallocations don't happen all the time they are. eg. Java, Haskell, Javascript ...

Is there a way that I can turn the content of an object property ...
hey there. anyone has any idea on how to pass a value from a select's options? is there any equivalent to sprintf in javascript? Why do you need it? do format a string. using google maps api, gives miles with a lot of decimal points. ...

Im not trying to be argumentative You said you changed the ...
I was thinking of the string function. what string function? sorry, text function replace(). oh. Is there a way to select static values as multiple rows instead of multiple columns ? like select 1,2,3,4,5 gives columns, but is there a ...

How do I get dynamic DataSources with iBATIS and Spring? (created)
JndiObjectFactoryBean"> <value>java:/comp/env/jdbc/VendorOnevalue> ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional