简体   繁体   中英

Pass Checkboxes values to JavaScript

I am declaring 5 checkbox values in myform with the name as "yourname". On clicking submit button javascript function will be called.

In the JS function, I need to pass this value into parent window.

MyHTML Code is:

<input type="checkbox" name="yourname" value="ankit">Ankit<br/>
<input type="checkbox" name="yourname" value="rahul">Rahul<br/>

.. and more

<input type=button value='Submit' onclick="post_value();">

For Example, Using Below JS Code will print all values to the parent window.

function post_value(){
    var yourname = ["ankit","rahul","vipin","abhishek"];
    alert(yourname);
    opener.document.f1.p_name.value = yourname;
    self.close();
}

Kindly Help,

Give id to all your checkboxes and Check which one is checked using document.getElementById('checkBoxId').checked

This will return you true/false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM