[thelist] Javascript function to disable certains parts of a form

jon steele jjsteele22 at yahoo.com
Sun Jun 23 23:12:01 CDT 2002


Hi David,

Try this function:

<script>
function disableIt(e){
	es = e.split(',');
	for(i=0;i<es.length;i++){
		currE = eval("document.f."+es[i]);
		currE.disabled = true;
	}
}

function enableAll(){
	for(i=0;i<document.f.elements.length;i++){
		document.f.elements[i].disabled=false;
	}
}
</script>

To use it, add an onclick event handler to your radio buttons. In the above, "f" is the name of
your form. The "enableAll" function is needed so you don't end up with a whole form which is
disabled :p.

<form name="f">

<input type="Radio" name="a" value="a"
onclick="enableAll();disableIt('b1,b2,b3,c1,c2,c3')"><br><br>
<input type="text" name="a1">
<input type="text" name="a2">
<input type="text" name="a3">

<input type="Radio" name="a" value="b"
onclick="enableAll();disableIt('a1,a2,a3,c1,c2,c3')"><br><br>
<input type="text" name="b1">
<input type="text" name="b2">
<input type="text" name="b3">

<input type="Radio" name="a" value="c"
onclick="enableAll();disableIt('b1,b2,b3,a1,a2,a3')"><br><br>
<input type="text" name="c1">
<input type="text" name="c2">
<input type="text" name="c3">

</form>

> I have a form with three seperate sections.
>
> I have those three sections seperated by lines and the user is to pick one
> section to fill out depending on their choice.
>
> I would like to disable the other two sections that are not selected.
> Sections are picked by a radio button at the top of each one.

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



More information about the thelist mailing list