Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inverting Checkboxes 1

Status
Not open for further replies.

Panthaur

IS-IT--Management
Jul 26, 2002
78
US
I have the following scenario in my program. In my HTML side of my code, I have something like the following;

<form name=manifest>
<input type=checkbox name=include0 value=YES>
<input type=checkbox name=include1 value=YES>
<input type=checkbox name=include2 value=YES>
<input type=checkbox name=include3 value=YES>
<input type=hidden name=listcount value=4>
</form>

I'm trying to write a function, that when the user clicks a button on the page that it will invoke this function, and invert the checked boxes, if checkboxes 1,2,3 are check, and 4 is not, then 1,2,3 should become uncheck, and 4 should check.

Believe me, I know that one I have isn't written correctly, but i'm not sure HOW to write it. Can anyone make the appropriate corrections to my code? I would be forever grateful.

function invertmarking() {
with (parent.data.document.manifest) {
for (i=0; i<parseInt(listcount.value)-1; i++) {
if (include + i.checked == true) {
include + i.checked == false;
} else if (include + i.checked == false) {
include + i.checked == true;
}
}
}
}

Many thanks,
Panthaur
 
I have a similar program. If the client clicks the cancel checkbox it unchecks the others. If nothing else the eval part may help you set the true name of the checkbox.

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
function clearQ(){
with(document.theForm){
if (CHK5.checked==true){
for (j=1; j<=length-1; j++) {
box = eval(&quot;CHK&quot;+j);
box.checked = false;
} // end for
} // end if
} // end with
} // end clearQ
</script>

<form action=&quot;&quot; name=&quot;theForm&quot;>
<INPUT TYPE=&quot;Checkbox&quot; NAME=&quot;CHK1&quot; onClick=&quot;clearQ()&quot;>Option 1.<br>
<INPUT TYPE=&quot;Checkbox&quot; NAME=&quot;CHK2&quot; onClick=&quot;clearQ()&quot;>Option 2.<br>
<INPUT TYPE=&quot;Checkbox&quot; NAME=&quot;CHK3&quot; onClick=&quot;clearQ()&quot;>Option 3.<br>
<INPUT TYPE=&quot;Checkbox&quot; NAME=&quot;CHK4&quot; onClick=&quot;clearQ()&quot;>Option 4.<br>
<INPUT TYPE=&quot;Checkbox&quot; NAME=&quot;CHK5&quot; onClick=&quot;clearQ()&quot;>Cancel options.<br>
</form>
 
Perhaps something like this?

function invertmarking() {
var f=parent.data.document.manifest;
for (i=0; i<f.elements.length; i++){
if(f.elements.name.indexOf('include')>-1){
f.elements.checked=!f.elements.checked
}
}
}
 
Awesome! That's exactly what I was looking for! Thanks Everyone!
 
Thanks for the information. It is exactly what I needed.

Panthaur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top