How to change DropDownList Selected value in Javascript?

前端 未结 2 1163
逝去的感伤
逝去的感伤 2020-12-15 22:51

how to change the selected value in javascript and get the selected value in codebehind page? AutoPostBack is set to false.

相关标签:
2条回答
  • 2020-12-15 23:32

    You can change it like this:

    var ddl = document.getElementById('ddl-id');
    var opts = ddl.options.length;
    for (var i=0; i<opts; i++){
        if (ddl.options[i].value == "some-value"){
            ddl.options[i].selected = true;
            break;
        }
    }
    
    0 讨论(0)
  • 2020-12-15 23:39
    //setting the value of a drop down list
    document.getElementById('my_drop_down').selectedIndex=2;
    
    0 讨论(0)
提交回复
热议问题