Dynamically enable/disable an element inside a form.

  • Thread starter Henrik Hjøllund Hansen
  • Start date
H

Henrik Hjøllund Hansen

Is there a way I can dynamically enable/disable an element inside a form. In
the ex below I would like to hide the Season (name=P3) if the user checks
the Calender options in the P2.

Can this be done, I guess I will have to use VBscript or javascript to
optain this

Thanks in advance

Henrik.


<tr>
<td>Financial or Calender year
</td>
<td>
<input type="radio" name="P2" value="F" CHECKED >Financial
(Default)<br>
<input type="radio" name="P2" value="C">Calender<br>
</td>
</tr>
<tr >
<td>Season (Only if Financial)
</td>
<td>
<select name="P3" size="1">
<option value="2003">2003
<option value="2004">2004
<option value="2005">2005
<option value="2006">2006
<option value="1997">1997
<option value="1998">1998
<option value="1999">1999
<option value="2000">2000
<option value="2001">2001
<option value="2002">2002
</select>
</td>
</tr>
 
D

Derek Clarkson

Hi Henrik,
You can use javascript to do it. The property is called disabled. Here's an
example:

<input type="button" id="myButton" value="Go!" />
<input type="text"
onKeyUp="document.getElementById('myButton').disabled=false;" />

Typing anything in the text field enables the button. You can used the same
type of code to disable things as well. Have a read around DOM references
for more info. I think there is a visible property as well but I have never
used it.

cio
Derek.
 
J

Jukka K. Korpela

Henrik Hjøllund Hansen said:
Is there a way I can dynamically enable/disable an element inside a
form.

In HTML, no.
In the ex below I would like to hide the Season (name=P3) if
the user checks the Calender options in the P2.

I don't quite see the logic behind this (maybe I don't understand the
words the way you do), but if you have said, in the form, that some
input is requested in some cases only, isn't this enough? After all,
you need to double-check such things in the form handler anyway.

What you _could_ consider adding, as an optional extra, is a piece of
JavaScript that makes the part invisible until a suitable selection has
been made elsewhere. This way the form would be fully functional
without JavaScript. Cf. to
http://www.cs.tut.fi/~jkorpela/forms/combo.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top