How to make javascript form autochange - "Onchange"?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2005
Posts: 3
Reputation: Philz is an unknown quantity at this point 
Solved Threads: 0
Philz Philz is offline Offline
Newbie Poster

How to make javascript form autochange - "Onchange"?

 
0
  #1
Aug 12th, 2005
Hello, I have this code:


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <select name="product" class="buy">
  2. <option value="products.php" selected>Select Term</option>
  3. <option value="products.php?item=1&term=1">2 Month</option>
  4. <option value="products.php?item=1&term=3">3 Months</option>
  5. <option value="products.php?item=1&term=6">4 Months</option>
  6. <option value="products.php?item=1&term=12">5 Months </option>
  7. </select>

I need to make it so as soon as you click that select box, it loads the url (value)... if anyone can help me that would be great!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: How to make javascript form autochange - "Onchange"?

 
0
  #2
Aug 12th, 2005
Loads it where?

Look at some of the code in this article: Creating an HTML "ComboBox" control

It demonstrates all the techniques you'll need to reference Select/Option controls, retrieve their values, and copy them into other controls.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 3
Reputation: Philz is an unknown quantity at this point 
Solved Threads: 0
Philz Philz is offline Offline
Newbie Poster

Re: How to make javascript form autochange - "Onchange"?

 
0
  #3
Aug 12th, 2005
Thanks for your help.Here's my code again:


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <select name="product" class="buy">
  2. <option value="products.php" selected>Select Term</option>
  3. <option value="products.php?item=1&term=1">2 Month</option>
  4. <option value="products.php?item=1&term=3">3 Months</option>
  5. <option value="products.php?item=1&term=6">4 Months</option>
  6. <option value="products.php?item=1&term=12">5 Months </option>
  7. </select>

When they click the "2 Month" value, it will load http://www.mydomain.com/products.php?item=1&term=1. Do you see what I'm trying to do? Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: How to make javascript form autochange - "Onchange"?

 
0
  #4
Aug 12th, 2005
Sure. Add on onChange handler:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <select name = "product" class="buy" onChange="JavaScript:mySelect(this);">

Code the mySelect function in the head/script section:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function mySelect(x)
  2. {
  3. window.location.href = "http://www.your_domain.com/" +
  4. x.options[x.selectedIndex].value;
  5. }

Some variation of that ought to do the trick.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC