Home Web Front-end JS Tutorial 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

May 16, 2016 pm 06:47 PM
form Checkbox

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to use Vue to implement multi-select boxes and radio buttons How to use Vue to implement multi-select boxes and radio buttons Nov 07, 2023 am 11:42 AM

How to use Vue to implement multi-select boxes and radio buttons Vue is a popular JavaScript framework that is widely used in web development. In Vue, we can easily implement various interactive effects, including multi-select boxes and radio button boxes. This article will introduce how to use Vue to implement multi-select boxes and radio buttons, and provide specific code examples. Implementing a multi-select box A multi-select box is used to allow the user to select multiple options. In Vue, we can use the v-model directive to implement two-way data binding of multi-select boxes. Here is a simple example

The relationship between multi-select box check and select all function in Vue document The relationship between multi-select box check and select all function in Vue document Jun 21, 2023 am 09:33 AM

With the continuous development and advancement of front-end technology, the application of the Vue framework is becoming more and more popular. In practical applications of Vue, the functions of checking multiple boxes and selecting all are often used. In the Vue documentation, the implementation methods of checking multiple selection boxes and selecting all are also very detailed. Multi-select box in Vue In Vue, the implementation method of multi-select box is very simple. You only need to use <inputtype="checkbox"> where you need to use multi-select box. When multiple selections need to be made

BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? Mar 04, 2025 pm 12:00 PM

BinaryX's token name change: from BNX to FOUR, and then to FORM, the deep meaning behind strategic adjustments BinaryX recently changed the token symbol from $FOUR to $FORM, which has attracted widespread attention from the industry. This is not the first time BinaryX has changed its name, and its token symbol has undergone a transition from BNX to FOUR. This article will explore in-depth the strategic intentions behind this series of name change. 1. Token name change process and strategic considerations BinaryX initially launched the $BNX token based on the BNB chain in 2021 to support its Play-to-Earn (P2E) gaming ecosystem. In early 2024, in order to optimize the economic model, BinaryX divided $BNX and gradually expanded to GameF

Solution to the multi-select box all-select function in Vue development Solution to the multi-select box all-select function in Vue development Jun 30, 2023 pm 02:00 PM

How to solve the problem of the select-all function of multi-select boxes in Vue development. In Vue development, we often encounter scenarios where we need to use multi-select boxes for batch operations, and sometimes we also need to implement a select-all function, that is, select all and multiple-select. When the box is selected, all sub-options must also be selected. This article will introduce how to use Vue to solve the problem of selecting all functions of multi-select boxes. Preparation work First, in Vue development, we need to use Vue's calculated properties and event binding. In the Vue component, define a data attribute to store the selection of the multi-select box.

Can there be multiple forms in html5? Can there be multiple forms in html5? Aug 01, 2022 pm 05:28 PM

There can be multiple forms in html5. The rules allow multiple form tags to be used in the same HTML page. However, in order to prevent the backend from not recognizing it when submitting, you need to add different IDs or classes to the form. The syntax is "<from action="url" id=" id value 1">Form element</from><from action="url" id="id value 2">Form element</from>.....".

PHP form processing: tips on using multi-select boxes, radio buttons and drop-down lists PHP form processing: tips on using multi-select boxes, radio buttons and drop-down lists Aug 07, 2023 pm 11:29 PM

PHP form processing: Tips for using multi-select boxes, radio buttons and drop-down lists In web development, forms are one of the important ways for users to interact with the website. The multi-select boxes, radio buttons and drop-down lists in the form are some common user input options. This article will introduce how to use PHP to process these form elements and give corresponding code examples. Multi-select box A multi-select box allows the user to select multiple options. In HTML, you can use &lt;inputtype="checkbox"&g

What is the tag that defines the form in html5 What is the tag that defines the form in html5 Jul 26, 2022 pm 04:26 PM

The tag defining a form in HTML5 is "<form>". The form tag is used to create an HTML form (form field) for user input to collect and transfer user information. All content in the form will be submitted to the server; the syntax "<form action="Submit Address" method="Submit Method " name="form name">form control</form>". A form can contain one or more form elements, such as input, select, and textarea.

Comprehensively organize elements related to form forms! Comprehensively organize elements related to form forms! Aug 05, 2022 am 11:45 AM

This article gives you a detailed summary of the knowledge points related to form elements in HTML. I hope it will be helpful to you!

See all articles