Re: enabling/disabling a text field

by Christopher Higgs <chiggs(at)unimelb.edu.au>

 Date:  Thu, 25 Jul 2002 09:51:28 +1000
 To:  Dane Robison <dane(at)strategic-design.com>
 Cc:  hwg-techniques(at)hwg.org
 References:  hotmail
  todo: View Thread, Original
G'Day Dane

At 06:56 PM 24/07/2002 -0400, you wrote:
>I've run into a form with two inputs that are troubling me. The first is a 
>pull-down menu with preset options, the last option being "other." The 
>second is a text field that needs to be disabled at first (can't type into 
>it). If the user should select the "other" option from the pull-down, the 
>text field would become enabled for them to type into.
>
>Is there an easy way to do this? Thanks!

Should be fairly simple using JavaScript:

Use an event handler for the text field so that "onFocus" a function if 
performed.  The function should be able to test the value of your select 
element and if not equal to "Other" then "onBlur", effectively removing 
focus for the item.  This will prevent users entering information into the 
field unless "Other" has been selected.

You may also want to insert an "onChange" function for the select element 
so that  content within the text field is deleted if "Other" is deselected, 
although this could also be performed "onSubmit" of the form.

Note: This solution will only work for users with JavaScript enabled.


Chris Higgs
Manager, New Learning Technology
ILFR, University of Melbourne
http://www.landfood.unimelb.edu.au/
Phone: +61 3 8344 9749  Fax: + 61 3 9348 2156

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA