Yes, but you will need to access the value:
alert(document.frm.gateway
or
var theSel = document.frm.gateway_dep;
alert(theSel[theSel.select
Main Topics
Browse All TopicsHi Experts
I need to capture the selected item's index number of select box using client side javascript.
im have the following form and select box gets populated using client side javascript:
<form name="frm" action="mygroup.aspx" method="post" onSubmit="return submitform();">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr><td>
<select name="gateway_dep" onchange="refreshDest()">
<option></option>
</select>
</td></tr>
<tr><td>
<select name="dest_dep" onchange="destchanged()">
<option></option>
</select>
</td></tr>
<tr><td>
<input name="submit" type="submit" value="Search">
</td></tr>
</table>
</form>
I need to get the value of selected item's index number on form submit. Any help plz.........?
regards
shaukat
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Not for points but for better code
pass the form object and the select object in the event
Do NOT call anything name="submit" it is reserved
and do NOT try to submit the the form in the function you call onSubmit
<script>
function submitForm(theForm) {
if (theForm.gateway_dep.selec
alert('Please select something');
theForm.gateway_dep.focus(
return false; // cancel submit
}
return true; // submits the form
}
function refreshDest(theSel) {
alert(theSel.options[theSe
}
</script>
<form action="mygroup.aspx" method="post" onSubmit="return submitform(this);">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr><td>
<select name="gateway_dep" onchange="refreshDest(this
<option></option>
</select>
</td></tr>
<tr><td>
<select name="dest_dep" onchange="destchanged(this
<option></option>
</select>
</td></tr>
<tr><td>
<input name="Submit" type="submit" value="Search">
</td></tr>
</table>
</form>
>> can you guys help me how to maintain the last selection in drop down on form submit
Sorry, not sure I understand what you want to do. Do you want to have the item that was selected on form submit still be selected after the form submission? Do you want to pass the selectedIndex from the last drop down to the server-side code?
Or, alternatively, can you explain what you're trying to do and what you need these values for? That might help us to provide suggestions.
what is the user seeing when he submits - the result from the server or another page or stays on the same page (form is targetting a new window for example)
If the user sees the result plus a new form, you need to look through the options and add
selected
to the option that has the same value as the reponse.form("gateway_dep"
well THAT was the missing information wasn't it?
either set a cookie or return the selected value in the page
<script>
var selVal = "<%=reponse.form("gateway_
function setSel() {
if (selVal=="") return; // nothing passed
var sel = document.forms[0].gateway_
for (var i=0;i<sel.options.length;i
if (sel.options[i].value==sel
sel.optins[i].selected=tru
break
}
}
}
window.onload=setSel;
or call setSel after populateion
Business Accounts
Answer for Membership
by: dakydPosted on 2007-10-05 at 07:31:04ID: 20022153
Once you have something that points to the select that you want, you can use the selectedIndex attribute. So, say you wanted the selected index number for the gateway_dep drop down, you could do this:
tedIndex);
var theSel = document.frm.gateway_dep;
alert(theSel.options.selec
The same goes for any other drop-down. You can also combine the two statements into one if you like. Hope that helps.