Ankit
Ankit

Reputation: 2256

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,

Upvotes: 0

Views: 9129

Answers (1)

niksvp
niksvp

Reputation: 5563

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

This will return you true/false.

Upvotes: 2

Related Questions