SeeIT Solutions
05-28-2005, 08:47 AM
Hi, I was just wondering how to make a submit button enabled when a checkbox is clicked (for a terms and conditions kinda thing).
Thanks
Thanks
|
||||
Submit button enableSeeIT Solutions 05-28-2005, 08:47 AM Hi, I was just wondering how to make a submit button enabled when a checkbox is clicked (for a terms and conditions kinda thing). Thanks Brandoe85 05-28-2005, 08:59 AM Try this: <html> <head> </head> <body> <form name="myForm" acton=""> Terms:<input type="checkbox" name="chk" onclick="if(this.checked) document.myForm.sub.disabled=false; else document.myForm.sub.disabled=true;"><br> <input type="submit" name="sub" disabled="true"> </form> </body> </html> SeeIT Solutions 05-28-2005, 09:03 AM thanks glenngv 05-30-2005, 11:37 AM You can simplify the code by using this.form to refer to the form and using the ! (not) operator. <input type="checkbox" name="chk" onclick="this.form.sub.disabled=!this.checked" /> Kor 05-30-2005, 11:47 AM Nice shortcut, glenngv object.attribute=!otherobject.attribute; I wonder if it works when value of the attribute is not a boolean, example if it is or it is not null glenngv 05-30-2005, 12:44 PM If you logical NOT a non-boolean value, the result will be a boolean. The non-boolean value will be internally casted to boolean and then it will be negated. See sample below. alert(!null); //true alert(!""); //true alert(!"blah"); //false alert(!"0"); //false These make no difference with these shortcuts that we usually use. var x=null; if (x) ... var y; if (y) ... |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum