Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very quick form field redirect question

Status
Not open for further replies.

PerlTrumpsPhp

Programmer
May 21, 2007
8
US
Just a quick question. I'm a Perl user, not so much JavaScript so bare with me.

I have a pulldown menu with X number of options. The value of the options are NOT urls but references that my script can decode. My question is this..

Say the form name is "templates" and the pulldown is named "choice". How do I make it redirect to my script, say " followed by the value of the "choice" menu?

Ie:
Code:
<form action="" method="get" name="templates">
<select name="choice">
<option value"frog">Cool Frogs</option>
<option value"turtles">Not tortouses</option>
</select></form>

When the user selects FROGS, I need them to go to

I know it's probably easier having a GO button, so I'll take that if someone can help.
 
Something like this should work:

Code:
<select name="choice" [!]onchange="this.location = '[URL unfurl="true"]http://www.go.com/cgi-bin/script.cgi?view='[/URL] + this.value;"[/!]>

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Should this work without a GO button or do I need to put one in?
 
I did try it before posting and it does not redirect without a GO button. I haven't used a GO button yet but it's odd that I'd have to use one if it changes the location onChange.
 
[1] The correct line is "window.location" ("this.location is not.) So stick to the latest try.

[2] You have typos in the option in order to really pick up the value. (It is not critical to the redirecting... only the value would not be picked up.)
[tt]
<option value[red]=[/red]"frog">Cool Frogs</option>
<option value[red]=[/red]"turtles">Not tortouses</option>
[/tt]
[3] If you mean "frogs"...
>When the user selects FROGS, I need them to go to...
In that case, it would ever be possible. It is only possible to choose turtles. Reason? It is scripted on the onchange handling. If you choose "frogs" when loaded, it is not changing anything. Hence, it won't redirect. Since you choose to redirect without recourse, "frogs" will never be a real candidate of being redirected to as query string. In order to let all material options available to redirect, you can do this (among other ways - I am user).
[tt]
<form action="" method="get" name="templates" [red]onchange="if (this.value != '') {window.location = ' + this.value;}"[/red]>
<select name="choice">
[red]<option value=""> - choose one - </option>[/red]
<option value"frog">Cool Frogs</option>
<option value"turtles">Not tortouses</option>
</select></form>
[/tt]
 
Amendment
I should have typed the onchange inside the select element, not in the form element! That is what I meant. Here's a re-take.
[tt]
<form action="" method="get" name="templates">
<select name="choice" [red]onchange="if (this.value != '') {window.location = ' + this.value;}"[/red]>
<option value=""> - choose one - </option>
<option value[red]=[/red]"frog">Cool Frogs</option>
<option value[red]=[/red]"turtles">Not tortouses</option>
</select></form>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top