Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Passing Variables

I have the following setup in an asp form:

<form action=nextframe.asp .......>
<input type=text name=userfield1>
<input type=text name=userfield2>

<input type=submit name="run nextframe.asp">
<input type=button name="run another win" onclick="parent.Display.location.href='anotherwin.asp?var1=userfield1&var2=userfield2'

I've tried several different iterations of the above (mixing in javascript/vbscript/asp) and nothing seems to work.  Thanks in advance for your help.

-Curt
0
v923146
Asked:
v923146
  • 4
  • 2
1 Solution
 
Holger101497Commented:
I don't have enough information to give a reliable answer, but I see two problems with your code that might cause your problem:

1] referencing. I assume that the frame you reference exists, but it should be at least "form.userfield1.value" to get the value of the textfields. (form elementes have a ".form" attribute that refers to the form that contains them)
2] You run into a problem as soon as one of the fields contains a space, because URLs cannot contains spaces. The answer here is to "escape" the value - that is standard URL-encoding, in fact the same one that the submit does when you click the button. It replaces all "illegal characters".
your onclick would have to look like this:
onclick="parent.Display.location.href='anotherwin.asp?var1='+escape(form.userfield1.value)+'&var2='+escape(form.userfield2.value)"
The escape translates the values to the same format as a submit would. If you try to evaluate the parameters in JavaScript, you can use unescape(value) to get the text that was originally typed in the textbox.

Let me know if this helped and don't accept somebody else's answer if it did.

Good luck!
0
 
Holger101497Commented:
I don't have enough information to give a reliable answer, but I see two problems with your code that might cause your problem:

1] referencing. I assume that the frame you reference exists, but it should be at least "form.userfield1.value" to get the value of the textfields. (form elementes have a ".form" attribute that refers to the form that contains them)
2] You run into a problem as soon as one of the fields contains a space, because URLs cannot contains spaces. The answer here is to "escape" the value - that is standard URL-encoding, in fact the same one that the submit does when you click the button. It replaces all "illegal characters".
your onclick would have to look like this:
onclick="parent.Display.location.href='anotherwin.asp?var1='+escape(form.userfield1.value)+'&var2='+escape(form.userfield2.value)"
The escape translates the values to the same format as a submit would. If you try to evaluate the parameters in JavaScript, you can use unescape(value) to get the text that was originally typed in the textbox.

Let me know if this helped and don't accept somebody else's answer if it did.

Good luck!
0
 
Holger101497Commented:
stupid server! Told me there was no response, but obviously it did at least listen, was just too busy to answer ;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
v923146Author Commented:
Thanks Holger, your #2 did the trick.  Submit your comment as an answer so I can accept it.
0
 
Holger101497Commented:
Glad to hear that it solved the problem!
I think #1 is a valid comment as well - which browser are you using? Netscape 4 and IE 4 are a LOT more generous when it comes to accessing variables. Try your code in NN3 or IE3, I don't think it'll work without the form.userfield1.value...

well... you can find everything Netscape has to say about escape/unescape at http://home.netscape.com/eng/mozilla/3.0/handbook/javascript/ref_d-e.htm#48073

I guess it's not much more helpful than what I told you, but just in case you care to read the official documentation ;-)

Good luck with your pages!
0
 
v923146Author Commented:
#1 is a valid comment - i was just lazy when typing out the example.

I am using IE 3.02 (or 4) as the preferred browser, but have been testing everything on netscape 4 as well.  Since those are the only browsers at my company, I'm not too concerned with the others :-)

Thanks again for your quick response.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now