开发者

vb.net aspx How do I set a select back to the default select after it's been changed?

开发者 https://www.devze.com 2023-01-16 16:15 出处:网络
I need to set a select back to it\'s default value after it\'s been changed based on certain conditions. 开发者_C百科 Any ideas?Not sure whether I understood your requirement correctly. You can use Ja

I need to set a select back to it's default value after it's been changed based on certain conditions. 开发者_C百科 Any ideas?


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

        }


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



                            }
0

精彩评论

暂无评论...
验证码 换一张
取 消