[thelist] javascript variable issue (continued)
Michael Pemberton
mpember at phreaker.net
Fri Aug 31 10:12:55 CDT 2001
replace:
eval("document.forms['quiz']." + argname + ".value=" + thisValue
+ ";");
with this:
eval("document.forms['quiz']." + argname + ".value='" + thisValue
+ "';");
This will result in the value being considered a string instead of an
object name.
ALBIE ATTIAS wrote:
>
> Hassan
>
> As you can see, it now almost works. The only snag is that the first three
> variables always seem to be undefined. I've tried to work out why but I
> can't spot it. Can you? Hopefully this'll be the last time I have to bother
> you.
>
> Cheers
>
> Albie Attias
>
> http://www.eurosimm.com/page1.htm
>
> -----Original Message-----
> From: Hassan Schroeder [mailto:hassan at webtuitive.com]
> Sent: 31 August 2001 15:33
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] javascript variable issue (continued)
>
> ALBIE ATTIAS wrote:
>
> > I made the changes you suggested but I'm now getting a javascript error on
> > page 2 saying "documents.forms.quiz.q1 is not an object". What am I doing
> > wrong?
>
> Your script's reference to the form name and the form name itself
> don't match --
>
> /* from script */
> eval("document.forms['quiz']." + argname + ".value=" + value + ";");
>
> <!-- in body -->
> <form name="page1answers" method="get" action="page3.htm">
>
> Also, the values aren't being set, so
>
> /* old */
> var value = pairs[i].substring(pos+1); // Extract the value
> value = unescape(value); // Store as a decoded value
> eval("document.forms['quiz']." + argname + ".value=" + value + ";");
>
> /* new - changing "value" to a non-reserved word :-) */
>
> var thisValue = pairs[i].substring(pos+1); // Extract the value
>
> thisValue = unescape(thisValue); // Store as a decoded
> value
> document.forms['quiz'].elements[argname].value = thisValue;
>
> > Also, assuming everything else is ok, what line(s) of code do I use on
> page3
> > to access my stored answers?
>
> Example: move the function code out of the head and put it where you want
> to display it --
>
> <!-- within the body -->
> <p>Your answers were as follows:<p>
>
> <script language="javascript">
>
> var query = location.search.substring(1); // Get query string
>
> var pairs = query.split("&"); // Split at ampersand
>
> for (var i=0; i < pairs.length; i++)
> {
> var pos = pairs[i].indexOf('='); // Look for "name=value"
>
> if (pos == -1) continue; // If not found, skip
>
> var argname = pairs[i].substring(0,pos); // Extract the name
>
> var value = pairs[i].substring(pos+1); // Extract the value
>
> value = unescape(value); // Store as a decoded value
> document.write(argname + " = " + value + "<br />");
> }
> </script>
>
> I'll leave the grading part to you :-)
>
> HTH!
> --
> H*
> Hassan Schroeder ----------------------------- hassan at webtuitive.com
> Webtuitive Design === (+1) 408-938-0567 === http://webtuitive.com
>
> -- creating dynamic Web sites and applications since 1994 --
>
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !
>
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !
--
Michael Pemberton
mpember at phreaker.net
ICQ: 12107010
More information about the thelist
mailing list