Hello, I have this code:

<select name="product" class="buy">
                  <option value="products.php" selected>Select Term</option>
                  <option value="products.php?item=1&term=1">2 Month</option>
                  <option value="products.php?item=1&term=3">3 Months</option>
                  <option value="products.php?item=1&term=6">4 Months</option>
                  <option value="products.php?item=1&term=12">5 Months </option>
                </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!

Recommended Answers

All 3 Replies

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.

Thanks for your help.Here's my code again:

<select name="product" class="buy">
                  <option value="products.php" selected>Select Term</option>
                  <option value="products.php?item=1&term=1">2 Month</option>
                  <option value="products.php?item=1&term=3">3 Months</option>
                  <option value="products.php?item=1&term=6">4 Months</option>
                  <option value="products.php?item=1&term=12">5 Months </option>
                </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

Sure. Add on onChange handler:

<select name = "product" class="buy" onChange="JavaScript:mySelect(this);">

Code the mySelect function in the head/script section:

function mySelect(x)
{
  window.location.href = "http://www.your_domain.com/"  +   
     x.options[x.selectedIndex].value;
}

Some variation of that ought to do the trick.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.