How do you do the equivalent of the code below (to keep the list item selected after a postback), when you are dynamically populating a dropdown with Javascript (see code 2)?
Code 1 :
<select name="Brand" onChange="changeBrand(this);" ID="Brand">
<option value="all" <%if request("Brand")="all" then response.Write "selected" end if%>>all</option>
<option value="Equanet" <%if request("Brand")="Equanet" then response.Write "selected" end if%>>Equanet</option>
<option value="PC World Business" <%if request("Brand")="PC World Business" then response.Write "selected" end if%>>PC World Business</option>
<option value="PC World Education" <%if request("Brand")="PC World Education" then response.Write "selected" end if%>>PC World Education</option>
<option value="Business Flag" <%if request("Brand")="Business Flag" then response.Write "selected" end if%>>Business Flag</option>
<option value="Cold" <%if request("Brand")="Cold" then response.Write "selected" end if%>>Cold</option>
</select>
Code 2 :
function changeBrand(elem)
{
var j, Brand;
var shiftText;
if(elem.selectedIndex == 0) //if they selected [select a day] stmt
return false; //do nothing and leave quietly
//Clear the second drop down of all but top [select a shift]
for (i = document.form1.LoadID.options.length - 1; i >= 1; i--) document.form1.LoadID.options = null;
document.form1.LoadID.selectedIndex = 0;
//add to list box
if (document.form1.Brand.selectedIndex == 1)
{
document.form1.LoadID.options[1] = new Option('Account', 'Account');
document.form1.LoadID.options[2] = new Option('Education', 'Education');
}
else if (document.form1.Brand.selectedIndex == 2)
{
document.form1.LoadID.options[1] = new Option('Account', 'Account');
}
else if (document.form1.Brand.selectedIndex == 3)
{
document.form1.LoadID.options[1] = new Option('Education', 'Education');
}
else if (document.form1.Brand.selectedIndex == 4)
{
document.form1.LoadID.options[1] = new Option('Business Flag', 'Business Flag');
}
else if (document.form1.Brand.selectedIndex == 5)
{
document.form1.LoadID.options[1] = new Option('Cold', 'Cold');
}
}
Code 1 :
<select name="Brand" onChange="changeBrand(this);" ID="Brand">
<option value="all" <%if request("Brand")="all" then response.Write "selected" end if%>>all</option>
<option value="Equanet" <%if request("Brand")="Equanet" then response.Write "selected" end if%>>Equanet</option>
<option value="PC World Business" <%if request("Brand")="PC World Business" then response.Write "selected" end if%>>PC World Business</option>
<option value="PC World Education" <%if request("Brand")="PC World Education" then response.Write "selected" end if%>>PC World Education</option>
<option value="Business Flag" <%if request("Brand")="Business Flag" then response.Write "selected" end if%>>Business Flag</option>
<option value="Cold" <%if request("Brand")="Cold" then response.Write "selected" end if%>>Cold</option>
</select>
Code 2 :
function changeBrand(elem)
{
var j, Brand;
var shiftText;
if(elem.selectedIndex == 0) //if they selected [select a day] stmt
return false; //do nothing and leave quietly
//Clear the second drop down of all but top [select a shift]
for (i = document.form1.LoadID.options.length - 1; i >= 1; i--) document.form1.LoadID.options = null;
document.form1.LoadID.selectedIndex = 0;
//add to list box
if (document.form1.Brand.selectedIndex == 1)
{
document.form1.LoadID.options[1] = new Option('Account', 'Account');
document.form1.LoadID.options[2] = new Option('Education', 'Education');
}
else if (document.form1.Brand.selectedIndex == 2)
{
document.form1.LoadID.options[1] = new Option('Account', 'Account');
}
else if (document.form1.Brand.selectedIndex == 3)
{
document.form1.LoadID.options[1] = new Option('Education', 'Education');
}
else if (document.form1.Brand.selectedIndex == 4)
{
document.form1.LoadID.options[1] = new Option('Business Flag', 'Business Flag');
}
else if (document.form1.Brand.selectedIndex == 5)
{
document.form1.LoadID.options[1] = new Option('Cold', 'Cold');
}
}