开发者

Pass Checkboxes values to JavaScript

开发者 https://www.devze.com 2023-02-04 00:32 出处:网络
I am declaring 5 checkbox values in myform with the name as \"yourname\". On clicking submit button javascript function will be called.

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 pare开发者_StackOverflow中文版nt 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消