I have tried many combinations, but none of them are working, and surprisingly, I don't end up getting an error. The select box ends up having nothing selected. I need to set the selected option of a select box by the value since I don't know the index. Is this possible? Here is my code:
Code:
<script language="javascript">
function fill_profiles()
{ // first, remove all what is in the listbox
document.form1.osprofile.disabled = false
my_listbox=document.form1.osprofile
//chosen=document.form1.vendor.value
while (my_listbox.options.length!=0)
my_listbox.options.remove(0);
var oOption = document.createElement("OPTION");
oOption.text=''
oOption.value='%';
my_listbox.options.add(oOption)
// now, fill it !
//alert(document.form1.vendor.value)
if (document.form1.vendor.value == '0') {
for (var m=0; m<esparray.length; m++)
// if you conditionally fill the list, put the condition here (for example : if (my_array[m][1]>"whatever"))
{
if (esparray[m] != '') {
var oOption = document.createElement("OPTION");
oOption.text=esparray[m];
oOption.value=esparray[m];
my_listbox.options.add(oOption)
}
}
}
if (document.form1.vendor.value == '1') {
for (var m=0; m<crarray.length; m++)
// if you conditionally fill the list, put the condition here (for example : if (my_array[m][1]>"whatever"))
{
if (crarray[m] != '') {
var oOption = document.createElement("OPTION");
oOption.text=crarray[m];
oOption.value=crarray[m];
my_listbox.options.add(oOption)
}
}
}
if (document.form1.vendor.value == '2') {
for (var m=0; m<natarray.length; m++)
// if you conditionally fill the list, put the condition here (for example : if (my_array[m][1]>"whatever"))
{
if (natarray[m] != '') {
var oOption = document.createElement("OPTION");
oOption.text=natarray[m];
oOption.value=natarray[m];
my_listbox.options.add(oOption)
}
}
}
if (document.form1.vendor.value == '3') {
for (var m=0; m<nokarray.length; m++)
// if you conditionally fill the list, put the condition here (for example : if (my_array[m][1]>"whatever"))
{
if (nokarray[m] != '') {
var oOption = document.createElement("OPTION");
oOption.text=nokarray[m];
oOption.value=nokarray[m];
my_listbox.options.add(oOption)
}
}
}
if (document.form1.vendor.value == '4') {
for (var m=0; m<transarray.length; m++)
// if you conditionally fill the list, put the condition here (for example : if (my_array[m][1]>"whatever"))
{
if (transarray[m] != '') {
var oOption = document.createElement("OPTION");
oOption.text=transarray[m];
oOption.value=transarray[m];
my_listbox.options.add(oOption)
}
}
}
if (document.form1.vendor.value == '5') {
for (var m=0; m<nuarray.length; m++)
// if you conditionally fill the list, put the condition here (for example : if (my_array[m][1]>"whatever"))
{
if (nuarray[m] != '') {
var oOption = document.createElement("OPTION");
oOption.text=nuarray[m];
oOption.value=nuarray[m];
my_listbox.options.add(oOption)
}
}
}
//
//
//
//
//
//Here is the line. I have done my_listbox.selectedValue and many other combos
my_listbox.selectedIndex = '<%=request.form("osprofile")%>';
return true; }
</script>
<form method=post name="form1" id="form1">
<p align=center><table><tr>
<!-- ****************************oil seals profiles****************************** -->
<td align=right>Vendor: </td>
<td><select name="vendor" id="vendor" onchange="fill_profiles()">
<option value="%" <%if request.form("vendor")="%" then%>selected<%end if%>></option>
<option value="0" <%if request.form("vendor")="0" then%>selected<%end if%>>ESP</option>
<option value="1" <%if request.form("vendor")="1" then%>selected<%end if%>>Chicago Rawhide</option>
<option value="2" <%if request.form("vendor")="2" then%>selected<%end if%>>National</option>
<option value="3" <%if request.form("vendor")="3" then%>selected<%end if%>>Fruedenberg - NOK</option>
<option value="4" <%if request.form("vendor")="4" then%>selected<%end if%>>Transcom</option>
<option value="5" <%if request.form("vendor")="5" then%>selected<%end if%>>Nu-Seals</option>
</select></td>
<td align=right>Profile: </td><td><select name="osprofile" id="osprofile" <%if request.form("osprofile") = "" then%> disabled <%end if%>></select></td>