...

View Full Version : Need help with checkbox yes/no



DataTalk
12-12-2010, 03:43 PM
Looking for a simple method to Toggle textbox yes/no using CheckBox

This example does not work!
But I hope this will help explain what I am trying to do



<SCRIPT LANGUAGE="JavaScript">
function YesOrNo() {
if(document.formname.checkboxname.checked)
{
document.formname.textname.disabled='Yes';
}
else
{
document.formname.textname.disabled='No';
}}
</SCRIPT>

<form name="formname">
<input type="text" size="10" name="textname">
<input type="checkbox" onclick="YesOrNo()" name="checkboxname" value="Yes">
</form>

DJCMBear
12-12-2010, 03:59 PM
Try this


var YesOrNo = (function() {
if(document.formname.checkboxname.checked) {
document.formname.textname.disabled = 'disabled';
} else {
document.formname.textname.disabled = '';
}
});


And for the form use beter markup


<form method="post" action="" name="formname">
<input type="text" size="10" name="textname" value="" />
<input type="checkbox" onclick="YesOrNo();" name="checkboxname" value="Yes" />
</form>

abduraooft
12-12-2010, 04:04 PM
<SCRIPT LANGUAGE="JavaScript">

PS: The language attribute is deprecated. Use type="text/javascript" instead.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum