views:

26

answers:

2

I need to set a select back to it's default value after it's been changed based on certain conditions. Any ideas?

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
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
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