[whatwg] suggestion

Ian Hickson ian at hixie.ch
Thu Jun 10 12:38:33 PDT 2004

On Tue, 8 Jun 2004, Judah Frangipane wrote:
> I was thinking of some sort of expression for the required field such as:
> <input type="text" name="spouses_name" required="if(maritalstatus.value=='married')" />

You can do this, but you have to do it backwards -- set the required
attribute when the other field changes. As in:

   Married: <input type="checkbox" name="married"
                   onchange="spouseName.required = checked">
   Spouse's name: <input type="text" name="spouseName">

(Although you're more likely to just toggle disabled instead of required,
to be honest.)

You could also do it in the "forward" way like this:

 <input type="text" name="spouses_name"
        onformchange="required = maritalstatus.value=='married'" />

...where onformchange fires every time the form changes.

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list