Westside2004
asked on
Can't set checkbox to false because my fieldname/idfield contains a PERIOD.????
How can I set this checkbox to false?
I have this function that gets called, the function does some other things, but the one thing it is not doing is setting my checkbox to false so its no longer "checked" visually. I do not get an error, it just does not work.
function chk(ob,ismaster,requiredCh eckBox) {
alert(requiredCheckBox);
requiredCheckBox.checked = false;
}
When I do the alert the value I see is : required_someUniqueIdField .streetAdd ress
There is clearly a period in my field names, but that is because they are dynamic and must be this way, but it seems to throw things off.
So in other words: requiredCheckBox.checked is really: required_someUniqueIdField .streetAdd ress.check ed = false;
Is there a way I can keep my current field name and achieve what I want given the fact there is a period in the field name?
Thanks,
-ws
I have this function that gets called, the function does some other things, but the one thing it is not doing is setting my checkbox to false so its no longer "checked" visually. I do not get an error, it just does not work.
function chk(ob,ismaster,requiredCh
alert(requiredCheckBox);
requiredCheckBox.checked = false;
}
When I do the alert the value I see is : required_someUniqueIdField
There is clearly a period in my field names, but that is because they are dynamic and must be this way, but it seems to throw things off.
So in other words: requiredCheckBox.checked is really: required_someUniqueIdField
Is there a way I can keep my current field name and achieve what I want given the fact there is a period in the field name?
Thanks,
-ws
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
I changed the fieldname so it does not have a period in it, but the code still does not work. Here is the complete code with explanation
I am creating a dynamic form builder where the user can choose a field and decide if this field is required or not. So if the user checks the box next to the field, that field will appear on a form ultimately. They also can click a checkbox next to the field and make it that field required or not when the form ultimately renders.
If they choose to make the field required, I automatically select the checkbox next to the field for them. However, if they deselect the checkbox next to the field, the required checkbox still remains checked and I want to make it UNCHECKED. It is a bit confusing, but I am hoping this makes sense.
function chk(ob,ismaster,requiredCh eckBox) {
var isCheck = ob.checked;
var d=document.getElementsByTa gName("inp ut");
var testAll = true;
for(var i=0;i<d.length;i++) {
if (!ismaster) {
// Sub- box was checked
if (d[i].type && d[i].type=='checkbox') {
if (d[i].name=='checkAll') {
var theMaster = d[i];
}
else {
testAll=(d[i].checked && testAll); // set testAll to false if any are false
}
}
}
else {
// Master box was checked
if(d[i].type && d[i].type=='checkbox' && d[i].name.indexOf((ismaste r))!=-1) d[i].checked = isCheck;
}
} // close for loop
if (!ismaster) theMaster.checked=testAll;
} // close function
The parameter I pass in is called "requiredCheckBox" I want to set this to false if the user unchecks the field.
-ws
I changed the fieldname so it does not have a period in it, but the code still does not work. Here is the complete code with explanation
I am creating a dynamic form builder where the user can choose a field and decide if this field is required or not. So if the user checks the box next to the field, that field will appear on a form ultimately. They also can click a checkbox next to the field and make it that field required or not when the form ultimately renders.
If they choose to make the field required, I automatically select the checkbox next to the field for them. However, if they deselect the checkbox next to the field, the required checkbox still remains checked and I want to make it UNCHECKED. It is a bit confusing, but I am hoping this makes sense.
function chk(ob,ismaster,requiredCh
var isCheck = ob.checked;
var d=document.getElementsByTa
var testAll = true;
for(var i=0;i<d.length;i++) {
if (!ismaster) {
// Sub- box was checked
if (d[i].type && d[i].type=='checkbox') {
if (d[i].name=='checkAll') {
var theMaster = d[i];
}
else {
testAll=(d[i].checked && testAll); // set testAll to false if any are false
}
}
}
else {
// Master box was checked
if(d[i].type && d[i].type=='checkbox' && d[i].name.indexOf((ismaste
}
} // close for loop
if (!ismaster) theMaster.checked=testAll;
} // close function
The parameter I pass in is called "requiredCheckBox" I want to set this to false if the user unchecks the field.
-ws
function TestCheckBox (theForm) {
for (ix=0; ix < theForm.elements.length; ix++) {
var fld = theForm.elements[ix];
///
if (fld.name == 'checkbox1.fld1') { fld.checked= false; break; }
}
return false;
}
</script>
<form>
<table>
<tr>
<td colspan="2"><input type="checkbox" name="checkbox1.fld1" checked>Option
</td>
<td>
<input type="button" value="Test " onclick="TestCheckBox(this
</td>
</tr>
</table>