简体   繁体   English

将Checkboxes值传递给JavaScript

[英]Pass Checkboxes values to JavaScript

I am declaring 5 checkbox values in myform with the name as "yourname". 我在myform中声明5个复选框值为“您的名字”。 On clicking submit button javascript function will be called. 在单击提交按钮时,将调用javascript函数。

In the JS function, I need to pass this value into parent window. 在JS函数中,我需要将此值传递到父窗口中。

MyHTML Code is: MyHTML代码是:

<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. 例如,使用下面的JS代码会将所有值打印到父窗口。

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 将ID分配给您所有的复选框,并使用document.getElementById('checkBoxId').checked选中哪个document.getElementById('checkBoxId').checked

This will return you true/false. 这将返回true / false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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