943,965 Members | Top Members by Rank

Ad:
Aug 12th, 2005
0

How to make javascript form autochange - "Onchange"?

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Philz is offline Offline
3 posts
since May 2005
Aug 12th, 2005
0

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

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Aug 12th, 2005
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Philz is offline Offline
3 posts
since May 2005
Aug 12th, 2005
0

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

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: What is wrong wtih my css?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript form managment on the fly!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC