W3C home > Mailing lists > Public > whatwg@whatwg.org > June 2004

[whatwg] suggestion

From: Ian Hickson <ian@hixie.ch>
Date: Thu, 10 Jun 2004 19:38:33 +0000 (UTC)
Message-ID: <Pine.LNX.4.58.0406101933130.26930@dhalsim.dreamhost.com>
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.   `._.-(,_..'--(,_..'`-.;.'
Received on Thursday, 10 June 2004 12:38:33 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:34 UTC