JS method for obtaining the display value of the drop-down box and determining the single-choice button, js single-Choice

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.