Javascript which radio button




















W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use , cookie and privacy policy.

Skip to content. Change Language. Related Articles. Table of Contents. Save Article. Improve Article. Like Article. Last Updated : 26 Jul, The value is never shown to the user by their user agent. Instead, it's used to identify which radio button in a group is selected. A radio group is defined by giving each of radio buttons in the group the same name.

Once a radio group is established, selecting any radio button in that group automatically deselects any currently-selected radio button in the same group. You can have as many radio groups on a page as you like, as long as each has its own unique name. For example, if your form needs to ask the user for their preferred contact method, you might create three radio buttons, each with the name property set to contact but one with the value email , one with the value phone , and one with the value mail.

The user never sees the value or the name unless you expressly add code to display it. Here you see the three radio buttons, each with the name set to contact and each with a unique value that uniquely identifies that individual radio button within the group.

If you omit the value attribute in the HTML, the submitted form data assigns the value on to the group. So don't forget to set your value attributes! Note: If no radio button is selected when the form is submitted, the radio group is not included in the submitted form data at all, since there is no value to report.

To get the value of selected radio button, a user-defined function can be created that gets all the radio buttons with the name attribute and finds the radio button selected using the checked property.

The checked property returns True if the radio button is selected and False otherwise. Example 1: The following program displays the value of selected radio button when user clicks on Submit button. Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof.

But before you tackle the big projects, we suggest you start by learning the basics. Now at it's lowest price ever! Skip to content.



0コメント

  • 1000 / 1000