JavaScript get checkbox check box get the selected option _javascript tips

Source: Internet
Author: User

Examples of the JavaScript get checkbox check box are countless, the following example, pure JS implementation of

var form = document.getElementById ("Form2");
var field = form.elements["Test2"];
var option = dining.getselectedoption (form, field);
var message = ""; for (var i = 0, len = option.length i < len; i++) {message = = "SELECT id:" + option[i].id + "\nselected Name:" + Opti
On[i].name + "\nselected value:" + option[i].value + "\ n";}
alert (message);  /* Get the selected option * * Getselectedoption:function (Selectform, Selectionfield) {var result = []; var option = null; for (var i = 0; i < selectionfield.length;

i++) {option = Selectionfield[i]; if (option.checked) {result.push (option);}

return result; <form id= ' Form2 ' > <label> sort: </label><input id= ' aaaaa ' type= ' checkbox ' name= ' test2 ' value= ' 1 ' > <label for= ' aaaaa ' > Monthly sales </label><input id= ' bbbbb ' type= ' checkbox ' name= ' test2 ' value= ' 2 ' > < Label for= ' bbbbb ' > Score </label><input id= ' CCCCC ' type= ' checkbox ' name= ' test2 ' value= ' 3 ' > <label for= ' CCCCC ' > Offers </label> <br style= ' CLEAr:both ' ><label> Category: </label><input id= ' ddddd ' type= ' checkbox ' name= ' test2 ' value= ' 4 ' > <label For= ' DDDDD ' > Business package </label><input id= ' eeeee ' type= ' checkbox ' name= ' test2 ' value= ' 5 ' > <label for= ' Eeeee ' > Cold dish </label><input id= ' fffff ' type= ' checkbox ' name= ' test2 ' value= ' 6 ' > </form> ',

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.