Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  137] [ 4]  / answers: 1 / hits: 34938  / 12 Years ago, sat, january 5, 2013, 12:00:00

I need help. When I submit this form I want it to automatically redirect to the value option (which is url) in the select list.



So on pressing submit for Ahmedabad selected in select list it should redirect to http://intranet.guj.nic.in/passport



Currently it is not redirecting. What is the best way to do it using inline javascript code?



<html><body>
<form id=pass-form >
<select id=pass-dropdown ><option selected=selected>Select Passport Office
for Status page </option><option value=http://intranet.guj.nic.in/passport/>Ahemadabad
</option><option value=http://passportstatus.nic.in/passmain.php?city=asr>Amritsar
</option><option value=http://rpobangalore.gov.in/npassport.asp>Bangalore
</option><option value=http://passportstatus.nic.in/passmain.php?city=bly>Bareilly
</option></select>
<input type=submit onsubmit=var sel = document.getElementById('pass-dropdown'); window.location = sel.options[sel.selectedIndex].value />
</form>
</body>
</html>

More From » html

 Answers
128

onsubmit is an event of the <form> element and not of the submit button.



Change your form code to:



<form id=pass-form onsubmit=window.location.href = 'newlocation'; return false;>
...
<input type=submit value=Submit />
</form>

[#81066] Friday, January 4, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;