How to get the display value of the drop-down box and determine the single-choice button in JS _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how to get the display value of the drop-down box in javascript and how to judge the single-choice button. It provides an example of how javascript performs operations on the html drop-down box and single-choice button, for more information about how to obtain the display value of the drop-down box and determine the single-choice button in JS, see the following example. 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:

BeijingShanghaiJiangsuHebei

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:

2009-05-202009-05-212009-05-222009-05-23

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.

Related Article

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.