Say I have a form that asks for a name and favorite color. There is a third elemet that asks for favorite food, but it is disabled (greyed out). Pretty basic html so far.

Now, add to the form a checkbox beside the name field. If a user clicks this checkbox the greyed out element becomes active.

Before the checkbox is selected the form looks like this:

Code:
<form action=test.cgi method=post>

Name? <input type=text name=name> <input type=checkbox name=addelement value=yes> List your favorite food?

Color? <input type=text name=color>

Food? <input type=text name=food disabled>

<input type=submit value=submit>

</form>

If the checkbox is selected the form looks like this:

Code:
<form action=test.cgi method=post>

Name? <input type=text name=name> <input type=checkbox name=addelement value=yes> List your favorite food?

Color? <input type=text name=color>

Food? <input type=text name=food>

<input type=submit value=submit>

</form>

The user can select and unselect the checkbox and the food input text box will select/deselect with each subsequent click.

I've done something vaguely similar - but only to change a value in an existing textbox, not to change an option for a text box.

Can this be done?