passing values Newbie question

A

Angi

I have looked through the first 672 messages and haven't found
anything similar to this so I'm sorry if this has been posted and I
didn't see it. I'm new to js, so PLEASE be patient with me! Thanks
in advance!

I posted the following message in a Frontpage newsgroup:
I need to carry values from one webpage form to another. I can't use
..asp, I
have to use html or dhtml. I've tried going through the VBA help
files and i
can't figure it out. I don't know what how to refer to the option
button that
was selected.

Here's what I'm trying to do, so if there is an easier way to do it,
PLEASE let
me know!

Select item (item# saved)
Select color (item # and color ID now saved)
Order form (info from above is already entered..only
personal info
needs to be entered)

I was told to refer to a faq that gave me the following script:
Input Page:
<form action="myPage.html">
BD30: <input type="radio" name="radio1" value="BD30">
ABD30: <input type="radio" name="radio1" value="ABD30">
<input type="submit">
</form>

myPage:
<script language="JavaScript"><!--
var passed=window.location.search.substring(1);
alert(passed);
//--></script>

Technically, it works, but it creates a message box telling me
radio1=BD30. I want it to be at the top of the page as just text (not
a text box, which I can do, but then it can be changed). The problem
is obviously in the myPage script, but I don't know enough yet to make
it do what I want. What am I supposed to be doing?

TIA again!
Angi
 
M

Michael Winter

try cookies - if both pages are on the same website

[snipped quoted text]

Was a 3KB+ post really necessary just to say that?

Please don't top-post.

Replies should be placed inline with the relevant quoted material.
Unrelated material should be deleted (and preferably marked as such).

Mike
 
A

Angi

Hal Rosser said:
try cookies - if both pages are on the same website

Forgive me, but first of all, I don't know how to create a cookie
(Newbie with javascript) and secondly, if a person doesn't accept
cookies, like me, that won't work, will it?

Also, I'm assuming you mean use a cookie to grab the values, which
would change all my code (1st & 2nd page)...right?

thx
 
M

Michael Winter

Forgive me, but first of all, I don't know how to create a cookie
(Newbie with javascript)

A Google search of both the Web and this group would have produced some
code.

For example, kaeli, a regular poster here, as a cookie collection:
and secondly, if a person doesn't accept cookies, like me, that won't
work, will it?

To be fair, relying on scripting is just as flawed as relying on cookies.
The *only* reliable approach is to store the values on the server and
refer to them later. However, you've ruled that out for whatever reason.
Also, I'm assuming you mean use a cookie to grab the values, which would
change all my code (1st & 2nd page)...right?

He means save the values to a cookie, and read them back on a later page.

Mike
 
R

Robert

(e-mail address removed) (Angi) wrote in message
myPage:
<script language="JavaScript"><!--
var passed=window.location.search.substring(1);
alert(passed);
//--></script>

Technically, it works, but it creates a message box telling me
radio1=BD30.

Delete the alert. You might want to change substring(1) to
substring(8).
I want it to be at the top of the page as just text (not
a text box, which I can do, but then it can be changed). The problem
is obviously in the myPage script, but I don't know enough yet to make
it do what I want. What am I supposed to be doing?

Do not know how you got the value in window.location.search since your
code does not show how.

You could use document.write to paste the string in your html file.
Something like:

<body>
<p>
<script type="text/javascript">
document.write("Passed value is " + passed);
</script>
</p>
</body>

This will set the value when the page loads. For something to change
after the page is loaded, you need to use innerHTHL.

Robert
 
M

Mick White

Angi said:
Robert,
Thanks for the reply. OK!! That worked...I don't understand why changing the
1 to an 8 made it work, but I'll take it.

Thanks so much!

var passed=location.search.split("=")[1]

Mick
 
R

Robert

Robert,
Thanks for the reply. OK!! That worked...I don't understand why changing the
1 to an 8 made it work, but I'll take it.

You could put these statements just before the variable definition:

alert(window.location.search);
alert("0.." + window.location.search.substring(0) + "\n" +
"1.." + window.location.search.substring(1) + "\n" +
"7.." + window.location.search.substring(7) + "\n" +
"8.." + window.location.search.substring(8) );

These statements should give you an idea of what is going on. I haven't tested them.
Thanks so much!

Glad to be of assistance.

Robert
 
M

Michael Winter

Mike,
Thank you for being gentle with the newbie!
:)

[snip]

I think you're talking about me not using .asp. My host doesn't allow
them so I needed to find another way to what I need to do.

There are other server-side languages. Any one of them should suffice.

[snip]
I understand the concept of a cookie, but I still don't know how to
refer to a form control after the window has closed.

You can't and the idea is that you don't need to. However, the approach
isn't appropriate in your case. I was merely pointing out what Hal was
referring to; I didn't intend to mislead you.

The intention was that the form values would be saved in the cookie and
held there during the transition to the next page. Here you could read the
values back (assuming cookies were supported).

What you began to do - pass the values through the URL - would be best if
server-side support isn't available. To find prepared code for parsing the
query/search string, search the archives:
<URL:http://groups.google.com/groups?q=group:comp.lang.javascript+parse+query+|+search+string>.

[snip]

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top