Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Enable field via Drop Down Selection

    Does anyone have an example of a script which will enable a "state" text field when "United States" is selected from a "country" drop down selection? By default "state" would be disabled.

    Thanks for any help!

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Like this?:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function controlField(obj){
    var t=obj.form['state'];
    if(obj.value.match(/United States/)){
    t.removeAttribute('disabled');
    t.focus();
    }
    else{
    t.value='';
    t.setAttribute('disabled','disabled');
    }
    }
    </script>
    </head>
    <body>
    <form>
    <select onchange="controlField(this)">
    <option value="">-  country -</option>
    <option value="Canada">Canada</option>
    <option value="United States">United States</option>
    <option value="UK">UK</option>
    </select>U.S State<input type="text" disabled="disabled" name="state">
    </form>
    </body>
    </html>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the info. This is very close. Is it possible to add more than one country? For example, if the United States or Canada was selected it would enable the State text field.

    Thanks again!

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    ...
    if(obj.value.match(/United States|Canada/)){
    ...
    See also RegExp:
    http://lawrence.ecorp.net/inet/samples/regexp-intro.php
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    jforena (01-18-2008)

  • #5
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Way cool, thank you Kor!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •