Forum Moderators: phranque
I'm trying to make some fields on a form conditionally disabled but after the function is used once in the script, the initial checkbox that it references is un-checkable
Here is the code i'm using...
The function...
function changeCheck() {if
(document.form1.base.checked=true){
//document.write('True selection');
document.form1.memory.disabled=false;
document.form1.processor.disabled=false;
document.form1.graphics.disabled=false;
document.form1.integration.disabled=false;
}
else if
(document.form1.base.checked=false){
document.form1.memory.disabled=true;
document.form1.processor.disabled=true;
document.form1.graphics.disabled=true;
document.form1.integration.disabled=true;
}
}
The html form...
<form name="form1" method="post" action="">
<table cellspacing=0 cellpadding=5 width="100%" border=0>
<tbody>
<tr>
<td class=PgHeading scope=col colspan=3 height=5></td>
</tr>
<tr>
<th class=PgHeading scope=col width="79%"> <div align=left>Specification and cost</div></th>
<th scope=col width="15%"> </th>
<th scope=col width="6%"> </th>
</tr>
<tr class=caption>
<td>Delcam SFF Dual OPT246 -2GB DDR -2x 120GB -128-DVD +/- RW**</td>
<td width="15%">£2200</td>
<td><p>
<input name="base" type="checkbox" id="base" value="1" onclick="changeCheck();">
</p></td>
</tr>
<tr class=caption>
<td>Upgrade to 4GB DDR Memory</td>
<td width="15%">£415</td>
<td width="20%"><input name="memory" type="checkbox" id="memory" value="1" disabled="true"></td>
</tr>
<tr class=caption>
<td>Upgrade to OPT250 Processors</td>
<td width="15%">£560</td>
<td><input name="processor" type="checkbox" id="processor" value="1" disabled="true"></td>
</tr>
<tr class=caption>
<td>Upgrade to nvidia FX3000 Graphics</td>
<td width="15%">£610</td>
<td><input name="graphics" type="checkbox" id="graphics" value="1" disabled="true"></td>
</tr>
<tr class=caption>
<td>19" Flat Panel Monitor</td>
<td width="15%">£475</td>
<td><input name="monitor" type="checkbox" id="monitor" value="1"></td>
</tr>
<tr class=caption>
<td>System Integration (first PC) *</td>
<td width="15%">£550/£300</td>
<td><DIV ID="MMDiv" style="color:gray"><input name="integration" type="checkbox" id="integration" value="1" disabled="true"></DIV></td>
</tr>
<tr class=caption>
<td>System Integration (additional PC's)</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input name="addtocart" type="submit" id="addtocart" value="Add to cart"></td>
<td width="15%"> </td>
<td width="6%"> </td>
</tr>
</tbody>
</table>
</form>
To clarify, when checking the 'base' checkbox for the first time, it behaves as expected and enables the other checkboxes. After this, when I try and check the 'base' checkbox again, it acts as if it's disabled
Any help would be GREATLY appreciated
Cheers
<input type="checkbox" name="whatever" value="1" readonly>
Or if you want to make it so people can't uncheck the box:
<input type="checkbox" name="whatever" value="1" readonly checked>
Is that what you are trying to do?
If yes then you'll have to check up on whether that uses javascript, I am not sure.
<added> If it doesn't then I would advise you to go with my example. Not only would it save space, some users don't have javascript and those which do can "cheat" and disable it in their browser, allowing them to check and uncheck the boxes at will </added>
<and added again> Doesn't work - just checked, but it works with text boxes
</and added again>
In IE if a javascript has errors, next to the Done sign there's a symbol telling you there are javascript errors. Double-click on the sign and it will tell you what line and col it is on. Can you tell us where the error is?
if (document.form1.base.checked=true)
and instead you should list:
if (document.form1.base.checked==true)
In the upper snippet the javascript is in fact CHANGING the checkbox's status to checked, rather than just evaluating it.
That fixed it for me, hope it fixes it correctly for you!