Home>

First, js selects the server control select and dropdownlist

1. js operation server control select

<select onchange="return showmessage ()">
 <option value="0"&​​gt;== Please select ==</option>
 <option value="1">is</option>
 <option value="2">No</option>
</select>
</p>
<p>
<script type="text/javascript" language="javascript">
 function showmessage () {
 if (document.getelementbyid ("selectid"). options [document.getelementbyid ("selectid"). selectedindex] .value == 1) {
 alert ("Hello, you chose the first one");
 document.getelementbyid ("txtcontractname"). setattribute ("enable", false);
 }
 else if (document.getelementbyid ("selectid"). options [document.getelementbyid ("selectid"). selectedindex] .value == 2) {
 alert ("Hello, you chose the second one");
 }
 }
</script>
</p>
<p>
//js operation server control dropdownlist
<asp:dropdownlist runat="server" skinid="ddlskin" autopostback="false" onselectedindexchanged="ddlfolder_selectedindexchanged">
 <asp:listitem value="0"&​​gt;option 0</asp:listitem>
 <asp:listitem value="1">option 1</asp:listitem>
</asp:dropdownlist>
<asp:dropdownlist runat="server" skinid="ddlskin" autopostback="false" onselectedindexchanged="ddlfolder_selectedindexchanged">
 <asp:listitem value="0"&​​gt;option 0</asp:listitem>
 <asp:listitem value="1">option 1</asp:listitem>
</asp:dropdownlist>

js code:

document.getelementbyid ("ddlfolder"). value="0";//0 is the value of the item i want to select

2. Select an item based on the text value setting

var dropdownlistcurrencynew=document.getelementbyid ("ddlfolder");
for (i=0;i<dropdownlistcurrencynew.options.length;i ++)
{
 if (dropdownlistcurrencynew.options [i] .text == "option0")
 {
 dropdownlistcurrencynew.options [i] .selected=true;
 }
}

Second, js read the value and text of the selected item in the dropdownlist

value:

var selvalue=document.getelementbyid ("dropdownlist1"). options [document.getelementbyid ("dropdownlist1"). selectedindex] .value;

text:

var seltext=document.getelementbyid ("dropdownlist1"). options [document.getelementbyid ("dropdownlist1"). selectedindex] .text;
  • Previous Detailed conversion of URL string and query string in nodejs
  • Next Nodejs operation mongoDB database example sharing