Home  >  Article  >  Web Front-end  >  Use Javascript to verify the checkbox value in the form_Form special effects

Use Javascript to verify the checkbox value in the form_Form special effects

WBOY
WBOYOriginal
2016-05-16 18:47:031162browse

This article introduces a more general method of obtaining checkbox value. I hope it will be useful to novices.

Copy code The code is as follows:



Like radio, the name is the same and there are multiple values. When getting the checkbox value, we cannot follow the ordinary text box.value method, but have to determine which one is selected.

When a group of checkboxes has multiple options, we can loop through checkbox[i] to determine whether an option is selected to return a value, but when a group of checkboxes has only one option, get The value method has changed again. In the code, (checkbox.checked)?checkbox.value:''; is used to directly determine whether it is selected, and then returns the corresponding value.

The parameter passed in the above code is the checkbox object, such as:
Copy the code The code is as follows:

var checkboxTest = document.forms['testForm'].elements['checkboxTest'];
if (getCheckboxValue(checkboxTest) == '')
{ ...... }

Perform the operation you want based on the judgment result.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn