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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop Down Box 1

Status
Not open for further replies.

khurram

IS-IT--Management
Jan 10, 2001
95
CA
I have a main page where there is a "Choose a country" drop down. When someone selects a country, I want the value (for example "United States" has a value of USD) to passed to the URL as well as proceed to the specified page.

Any ideas?
 
Hey Khurram,

I think this will do what you want.

<select name=&quot;loc&quot;
onchange=&quot;if (this.selectedIndex > 0 )
self.location.href='newScript.cfm?loc=' + this[this.selectedIndex].value;&quot;
>

This requires that the <option> tags have a value attribute like this:
<option value=&quot;usd&quot;>. Without the &quot;value=usd&quot; attribute, this doesn't work in Netscape at least. Also, the &quot;if (this.selectedIndex > 0)&quot; keeps it from submitting if the first element is selected. This is for selects where the first element is an instruction like &quot;Choose from below..&quot;. If all of your elements should be selectable, just remove the &quot;if&quot; statement.

Hope this helps,
GJ
 
Now if I have a button right beside the drop down labeled Go, how do make it so that in case it automatically doesn't proceed to the specifed page (for whatever reason like the customer browsing around, etc.) that once they click on the button, it will have the desired effect?
 
Either way you're sending the value of the select box so I wouldn't think there would be any difference. Am I missing something?

GJ
 
Sometimes I've noticed you can select a country (US), go ahead, press the back the button, click on the drop down and select US again and nothing happens. In that case, the customer should be able to press the GO button and proceed again.

 
I believe that happens when they choose the entry that was previously selected. The &quot;onchange&quot; event handler doesn't execute if they select the same entry so a &quot;go&quot; button is necessary in this case (or if they have JS disabled).

GJ

 
That's my question. How do I make the GO button work?

Thanks.
 
Are you talking about a submit button as in <input type=&quot;submit&quot;> or are you talking about an image that they click on as in <input type=&quot;image&quot; src=&quot;...>? If you put either one of these between your <form> and </form> tags, it will submit the form when clicked. Let me know if I'm missing something.

GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top