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

OnChange Submit form

Status
Not open for further replies.

netcashin

Programmer
Nov 13, 2000
159
US
With a dropdown box, I would like for the form to be submitted when a option is selected.

What should I set the OnChange to for the dropdown box or is that the wrong way to go?

Thanks

 
onchange = "document.forms[0].submit();"

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
- Quote by Douglas Adams
 
I'm pretty sure that's the only way to go.

SOP is to set onChange to be a javascript function you build that pretty much just contains the following:
Code:
<script type=&quot;text/javascript&quot; language=&quot;JavaScript&quot;>
function dropdownRedirect(){
  var dropdown = document.forms[&quot;[i]your_form_name[/i]&quot;].elements[&quot;[i]your_dropdown_name[/i]&quot;];
  var URL = dropdown.options[dropdown.selectedIndex].value;
  window.location.href = URL;
  return true;
}
</script>

and the dropdown would look something like:
Code:
<form action=&quot;javascript:void(0);&quot; method=&quot;post&quot; name=&quot;[i]your_form_name[/i]&quot; id=&quot;[i]your_form_name[/i]&quot; onSubmit=&quot;javascript:dropdownRedirect();return false;&quot;>

<select name=&quot;[i]your_dropdown_name[/i]&quot; SIZE=&quot;1&quot; onChange=&quot;javascript:dropdownRedirect();&quot;>
<option value=&quot;#&quot; SELECTED == SELECT A SITE ==</option>
<option value=&quot;[URL unfurl="true"]http://myurl_1/&quot;>Site[/URL] name 1</option>
<option value=&quot;[URL unfurl="true"]http://myurl_2/&quot;>Site[/URL] name 2</option>
<option value=&quot;[URL unfurl="true"]http://myurl_3/&quot;>Site[/URL] name 3</option>
</select>
</form>



-Carl
 
Sorry... misread the question.
bombboy is completely right. For some reason I read you were trying to redirect the browser instead of submit the form.

Long night. [hammer]


-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top