I need to set a select back to it's default value after it's been changed based on certain conditions. Any ideas?
views:
26answers:
2
A:
Not sure whether I understood your requirement correctly. You can use JavaScript for that.
function SetDefault() {
document.getElementById('Select1').selectedIndex = 0; //If first item is default
}
Shoban
2010-09-16 15:44:12
I don't know what the default will be. It could be the first, the last or anywhere in the middle. I want to do it with javascript, but I don't know how to use defaultselected.
Anthony
2010-09-16 15:52:50
A:
I had to loop through the select options to see which one was defaulSelected == true Then select it.
defaultVal and Val are defined elsewhere. If they are not the same we set the select option to equal the users PIN. If they are the same we set the select option back to the default select
var ReviewUpdaterList = document.getElementById("Review_Updater");
var A = ReviewUpdaterList.options, L = A.length;
if (defaultVal != Val)
{
var selectVal = '<%= Session("PIN")%>';
while(L)
{
if (A[--L].value == selectVal)
{
ReviewUpdaterList.selectedIndex= L;
L = 0;
}
}
}
else
{
while(L)
{
if (A[--L].defaultSelected == true)
{
ReviewUpdaterList.selectedIndex= L;
L = 0;
}
}
}
Anthony
2010-09-16 18:18:25