JS method for obtaining the display value of the drop-down box and determining the single-choice button, js single-Choice
This article describes how to get the display value of the drop-down box and determine the single-choice button in JS. Share it with you for your reference. The details are as follows:
1. I have done many projects and need to get the value displayed by the select component. The following are my frequently used methods:
The Html source code is as follows:
<Html> <body> <select id = "province" name = "province"> <option value = "1"> Beijing </option> <option value = "2"> shanghai </option> <option value = "3"> Jiangsu </option> <option value = "4"> Hebei </option> </select> <br/> <input type = "text" id = "provinceName" name = "provinceName"/> <input type = "button" onClick = "setTxt () "value =" assign value "/> </body>
The JS functions are as follows:
Function setTxt () {var _ selObj = document. getElementByIdx_xx ('province '); // retrieve the element var _ selVal = _ selObj [_ selObj. selectedIndex]. text; // retrieves the selected document from the drop-down list. getElementByIdx_xx ('provincename '). value = _ selVal ;}
2. I have also done a lot to determine whether the radio button is selected. The following are my frequently used methods:
The source code of the HTML page is as follows:
<Html> <body> <input type = "radio" name = "time" value = "2009-05-20"/> 2009-05-20 <input type = "radio" name = "time" value = "2009-05-21"/> 2009-05-21 <input type = "radio" name = "time" value = "2009-05-22"/> 2009-05-22 <input type = "radio" name = "time" value = ""/> <input type = "button" value = "determine whether to select" onclick = "alert (judge ()) "/> </body>
JS function code:
Function judge () {var status = false; var _ radObj = document. getElementsByName ('time'); for (var I = 0; I <_ radObj. length; I ++) {if (_ radObj [I]. checked) {status = true ;}} if (! Status) {alert ('unselected time! ');} Return status ;}
I hope this article will help you design javascript programs.