J
jedimasta
Good evening all,
I'm a relatively new to javascript, but I've been working with
ColdFusion and PHP for years so I'm not necessarily ignorant, just
stuck and frustrated. Using ColdFusion I'm using an include to pull in
form elements (text fields, checkboxes, etc...) multiple times on a
single page.
The included page does not have a form tag of it's own, but the root
page has uniquely named forms for validation. Imagine it like this:
<form name="form1">
<cfinclude tempalte="formtemplate">
</form>
<form name="form2">
<cfinclude tempalte="formtemplate">
</form>
I've got a simple check-one-box-and-check-em-all script INSIDE the
included template. I want to reference very specifically the form name,
and only check the boxes inside that form, not the others.
Unfortunately, I'm not syntax savvy and my attempts to use:
<form name="form1">
<input type="checkbox" id="chkAllNorth"
onClick="chkAll('chkAllNorth','northChk',this.form)">
</form>
does nothing. I can remove the this.form from the function entirely,
but it checks ALL the specified boxes with that ID in ALL the forms on
the page. Any help is appreciated. Here is the script:
function chkAll(thisBox,group,thisForm){
var inputs = document.thisForm.getElementsByTagName("input");
if(document.thisForm.getElementById(thisBox).checked == true){
for (i=0;i<inputs.length;i++){
if(inputs.id == group){
inputs.checked = 1;
}
}
}else{
for (i=0;i<inputs.length;i++){
if(inputs.id == group){
inputs.checked = 0;
}
}
}
return true;
}
I'm a relatively new to javascript, but I've been working with
ColdFusion and PHP for years so I'm not necessarily ignorant, just
stuck and frustrated. Using ColdFusion I'm using an include to pull in
form elements (text fields, checkboxes, etc...) multiple times on a
single page.
The included page does not have a form tag of it's own, but the root
page has uniquely named forms for validation. Imagine it like this:
<form name="form1">
<cfinclude tempalte="formtemplate">
</form>
<form name="form2">
<cfinclude tempalte="formtemplate">
</form>
I've got a simple check-one-box-and-check-em-all script INSIDE the
included template. I want to reference very specifically the form name,
and only check the boxes inside that form, not the others.
Unfortunately, I'm not syntax savvy and my attempts to use:
<form name="form1">
<input type="checkbox" id="chkAllNorth"
onClick="chkAll('chkAllNorth','northChk',this.form)">
</form>
does nothing. I can remove the this.form from the function entirely,
but it checks ALL the specified boxes with that ID in ALL the forms on
the page. Any help is appreciated. Here is the script:
function chkAll(thisBox,group,thisForm){
var inputs = document.thisForm.getElementsByTagName("input");
if(document.thisForm.getElementById(thisBox).checked == true){
for (i=0;i<inputs.length;i++){
if(inputs.id == group){
inputs.checked = 1;
}
}
}else{
for (i=0;i<inputs.length;i++){
if(inputs.id == group){
inputs.checked = 0;
}
}
}
return true;
}