Javascript checks whether the check box is selected

Source: Internet
Author: User

Javascript checks whether the check box is selected. The following example shows how to check the check box (there are currently a set of check boxes ):

<Input type = "checkbox" name = "fruit" value = "apple"/> apple <input type = "checkbox" name = "fruit" value = "orange"/> orange <input type = "checkbox" name = "fruit" value = "banana"/> banana <input type = "checkbox" name = "fruit" value = "grape"/> grape

You can obtain the value of a set of check boxes for name = fruit as follows:

<Script language = "javascript"> function checkbox () {var str = document. getElementsByName ('fruit'); var strLen = str. length; var checkVal = ''; for (I = 0; I <strLen; I ++) {if (str [I]. checked = true) {checkVal + = str [I]. value + ',';} if (checkVal = '') {alert (" Please select the check box first ~! ");} Else {alert (" check box value: "+ checkVal) ;}</script>
Articles you may be interested in
  • Jquery checks whether the check box is selected
  • Jquery checks whether checkbox is selected
  • Js determines whether the variable is a number
  • Js determines whether a value exists in a js Array
  • Js to determine whether an array contains repeated values
  • Jquery checks whether the page has been loaded with the jquery File
  • JQuery determines whether an element exists
  • Js checks whether the image is loaded and obtains the image width.

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.