Ninjakreborn Posted May 8, 2007 Share Posted May 8, 2007 I am disabling form fields with javascript. function start() { form1.relate.disabled = true; form1.tl2.disabled = true; form1.ftn2.disabled = true; form1.ltn2.disabled = true; form1.a12.disabled = true; form1.a22.disabled = true; form1.tc2.disabled = true; form1.psc2.disabled = true; form1.phone2.disabled = true; form1.email2.disabled = true; } // this launches the start function on load. onload = start; function enable() { form1.relate.disabled = !form1.activate.checked; form1.tl2.disabled = !form1.activate.checked; form1.ftn2.disabled = !form1.activate.checked; form1.ltn2.disabled = !form1.activate.checked; form1.a12.disabled = !form1.activate.checked; form1.a22.disabled = !form1.activate.checked; form1.tc2.disabled = !form1.activate.checked; form1.psc2.disabled = !form1.activate.checked; form1.phone2.disabled = !form1.activate.checked; form1.email2.disabled = !form1.activate.checked; } But it's still passing those fields to the php page even when there disabled, any advice. Quote Link to comment Share on other sites More sharing options...
xenophobia Posted May 8, 2007 Share Posted May 8, 2007 form1.activate is a checkbox? So your page contain a checkbox when user click on it, all the fields will disable/enable based on the checkbox's status? Another question, do you wish to disabled the whole form once user check the box? Consider you say yes, since you have so many fields. Put this for your javascript: function disableForm(st){ var the_form = window.document.form1; //change form1 to your form name for(var i=0; i<the_form.elements.length; i++){ the_form.elements[i].disabled = !st; } } Put this for your HTML: <form name="form1" action="testpad.php" method="post"> <input type="text" name="text1" size="15" /><br /> <input type="text" name="text2" size="15" /><br /> <input type="submit" value="Go" /> </form> <input type="checkbox" name="activate" onclick="disableForm(this.checked);" checked="checked" /> This will disable the entire form being post. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted May 8, 2007 Author Share Posted May 8, 2007 Ah, perfect. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.