CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Changing two values with one pull-down in a form?

 



Chef
Deleted

Mar 6, 2001, 4:06 PM

Post #1 of 2 (323 views)
Changing two values with one pull-down in a form? Can't Post

Hi!

I need to change two values in a form by using one pulldown-menu ... for example:

<select size="1" name="car">
<option value="blue car">blue car</option>
<option value="red car">red car</option>
<option value="yellow car">yellow car</option>
</select>

If anyone chooses "red car" the variable "price" should look like:

<input type="hidden" name="price" value="199">

if he chooses another model the content of "price" should change to a specific value ...

Any code-snippet for me?

Any help is appreciated!
Chef



rGeoffrey
User / Moderator

Mar 7, 2001, 12:50 PM

Post #2 of 2 (318 views)
Re: Changing two values with one pull-down in a form? [In reply to] Can't Post

If you want to change another value in the form you can have the select field use an 'onChange' option.

Here is an example that I use to set another select box and place a value into a text box...


Code
<select name="sampleid" 
onChange="this.form.id.value = this.form.sampleid.options[this.form.sampleid.selectedIndex].value;
this.form.type.selectedIndex = this.form.sampleid.selectedIndex;">

However, you probably don't need this heavy a solution in this case. As you are storing the value in a hidden field, the user will not see it, and thus does not notice that the value is changing. So you can change your option tags to hold both bits of information directly...


Code
<option value="red car---199">red car</option>

And then have your script do a split on '---' to get the two values.

This will eliminate any worries about the user not using javascript or the fact that if they accept the default option, then there was no change, so the onChange effect never happens.

--
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives