www.webdeveloper.com
Results 1 to 3 of 3

Thread: Active Text Box

  1. #1
    Join Date
    May 2012
    Posts
    2

    Active Text Box

    I have the following scenario using a form:

    A dropdown with 20 values, with the last being 'other'. When the user selects 'other' they should enter information in an adjacent text box. The text box should be disabled unless 'other' is selected. Is there a way to accomplish this? Of course, I'm open to other ideas as well

    Thanks

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,669
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    </head>
    <script type="text/javascript">
    <!--
    
    function Other(sel,nme){
     var frm=sel.form;
     if (sel.value=='other'){
      frm[nme].removeAttribute('disabled');
     }
     else {
      frm[nme].disabled='disabled';
      frm[nme].value='';
    
     }
    }
    
    //-->
    </script>
    <body>
    <form>
    
    <select onchange="Other(this,'other');">
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="" >1</option>
     <option value="other" >other</option>
    </select>
     <input name="other" type="text" disabled="disabled"  value="">
    </form>
    </body>
    
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    May 2012
    Posts
    2
    Thank you for posting this code, I was able to make it work with my site.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles