Jump to content

[SOLVED] javascript disabling


Ninjakreborn

Recommended Posts

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.

Link to comment
Share on other sites

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.  ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.