Help with simple if-then

M

Mike Bahr

Hi All,

Im not very well versed in javascript at all so hoping someone can help me
out here.

I have a page that uses pairs of radio buttons to toggle visibility of some
table columns.
I need to convert the radio button pairs to a single checkbox so Im thinking
just a function to check the status of the checkbox and "SHOW" if checked,
and "HIDE" if not checked.

Here are my radio buttons:
<!-- Show/Hide Column 1 -->
<input type="radio" name="Col1Visibility" checked="checked"
onclick="ChangeColumnVisibility('visible', 0);">
<input type="radio" name="Col1Visibility"
onclick="ChangeColumnVisibility('collapse', 0);">
<!-- Show/Hide Column 2 -->
<input type="radio" name="Col2Visibility" checked="checked"
onclick="ChangeColumnVisibility('visible', 1);">
<input type="radio" name="Col2Visibility"
onclick="ChangeColumnVisibility('collapse', 1);">
<!-- Show/Hide Column 3 -->
<input type="radio" name="Col3Visibility" checked="checked"
onclick="ChangeColumnVisibility('visible', 2);">
<input type="radio" name="Col3Visibility"
onclick="ChangeColumnVisibility('collapse', 2);">

And so on...

I need to figure out a "Toggle" function for my checkbox
<!-- Show/Hide Column 1 -->
<input id="Col1Visibility" type="checkbox" checked="CHECKED"
onclick="Toggle('ChangeColumnVisibility???', 0);" />
<!-- Show/Hide Column 2 -->
<input id="Col2Visibility" type="checkbox" checked="CHECKED"
onclick="Toggle('ChangeColumnVisibility', 1);" />
<!-- Show/Hide Column 3 -->
<input id="Col3Visibility" type="checkbox" checked="CHECKED"
onclick="Toggle('ChangeColumnVisibility', 2);" />
<!-- Show/Hide Column 4 -->
<input id="Col4Visibility" type="checkbox" checked="CHECKED"
onclick="Toggle('ChangeColumnVisibility', 3);" />

Should be something like:
Function Toggle...
if checkbox is checked, then ChangeColumnVisibility('visible', 0);
else
ChangeColumnVisibility('collapse', 0);
But Im not sure of the syntax nor how to get the column number.

Can you help me out with this?

Thanks a TON in advance!
 
M

Mike Bahr

Hey - Got if figured out!
Maybe review to see if it could be done better?

function ToggleColumn(obj_checkbox, n)
{
if(obj_checkbox.checked)
{
ChangeColumnVisibility('visible', n);
}
else
{
ChangeColumnVisibility('collapse', n);
}
}

<input id="Column1" type="checkbox" checked="CHECKED"
onclick="ToggleColumn(this, 0);" />

Thanks
 

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,119
Latest member
IrmaNorcro
Top