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.