Grabbing Checkbox Value

E

evanburen

I'm passing the name of a div and the name of checkbox to this function
which either hides or displays the div. My problem is this line

// var the_box = window.document.frmCheckboxes.chkCompanyBoard;

I want to assign the name of the checked checkbox to var the_box rather
than just hard-code chkCompanyBoard


function hideLayer2(whichLayer,the_box)
{
var the_box = window.document.frmCheckboxes.chkCompanyBoard;
var the_switch = "";
if (the_box.checked == false) {
document.getElementById(whichLayer).style.display = 'none';
var strshowhide=0;
frmPanelStatus.location.href="panelstatus.asp?showhide=" +
strshowhide + "&whichLayer=" + whichLayer;
} else {
document.getElementById(whichLayer).style.display = 'inline';
var strshowhide=1;
frmPanelStatus.location.href="panelstatus.asp?showhide=" +
strshowhide + "&whichLayer=" + whichLayer;

}

}

<form name="frmCheckboxes">
<table border="0" width="95%" align="center">
<tr>
<td><input type="checkbox" name ="chkCompanyBoard"
onClick="hideLayer2('CompanyBoard',this);">Company and Board
Description</td>
<td><input type="checkbox" name ="chkEvents"
onClick="hideLayer2('Events',this);">Events Reported For This
Company</td>
<td><input type="checkbox" name ="chkAboutBoard"
onClick="hideLayer2('AboutBoard',this);">About the Board</td>
</tr>
<tr>
<td><input type="checkbox" name ="chkCommittees"
onClick="hideLayer2('Committees');">Current Committee Assignments</td>
<td><input type="checkbox" name ="chkTransactions"
onClick="hideLayer2('Transactions');">Related Party Transactions</td>
<td><input type="checkbox" name ="chkConnections"
onClick="hideLayer2('Connections');">Director Connections</td>
</tr>

</table>
</form>


<div id="CompanyBoard">stuff</div>
<div id="Events">stuff</div>
<div id="AboutBoard">stuff</div>
 
L

Lee

(e-mail address removed) said:
I'm passing the name of a div and the name of checkbox to this function
which either hides or displays the div. My problem is this line

// var the_box = window.document.frmCheckboxes.chkCompanyBoard;

I want to assign the name of the checked checkbox to var the_box rather
than just hard-code chkCompanyBoard


function hideLayer2(whichLayer,the_box)
{
var the_box = window.document.frmCheckboxes.chkCompanyBoard;

Delete the line above, and your problem is solved.
By passing "this" from the event handler, the value of "the_box"
is a reference to the_box, exactly as in your hard-coded example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top