SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    Phil fillup07's Avatar
    Join Date
    May 2002
    Location
    Jacksonville, FL
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display a text box when dropdown list says Other

    I need a text box to display next to a drop down list whenever the drop down list says "other". Can someone please help, I have no idea how to do this.

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <style type="text/css">
    #bar {visibility:hidden;}
    </style>
    <script>
    function show(el, vis){
    	var elem = document.getElementById(el);
    	elem.style.visibility = (vis) ? 'visible' : 'hidden';
    }
    </script>
    </head>
    
    <body>
    <form>
    <input type="radio" name="foo" value="1" onclick="show('bar',false)">1 <br>
    <input type="radio" name="foo" value="2" onclick="show('bar',false)">2 <br>
    <input type="radio" name="foo" value="other" onclick="show('bar',true)">other 
      <span id="bar"><input type="text"></span>
    </form>
    </body>
    </html>
    ----Adopt-a-Sig----
    Your message here!

  3. #3
    Phil fillup07's Avatar
    Join Date
    May 2002
    Location
    Jacksonville, FL
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but I need it in a drop down list. I tried this code, but it doesn't work...

    Code:
    <html>
    <head>
    <style type="text/css">
    #bar {visibility:hidden;}
    </style>
    <script>
    function show(el, vis){
    	var elem = document.getElementById(el);
    	elem.style.visibility = (vis) ? 'visible' : 'hidden';
    }
    </script>
    </head>
    <body>
    <form method="POST">
      <select size="1" name="thename" class="asdf">
      <option selected>--- Choose One ---</option>
      <option onclick="show('bar',false)">choice 1</option>
      <option onclick="show('bar',false)">choice 2</option>  
      <option onclick="show('bar',true)">other</option>
      </select><span id="bar"><input type="text"></span>
      <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
    </form>
    </body>
    </html>

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was gonna do this using the options' values to hold the true and false data, but I thought you'd probably need the value for something else...so this should do it
    Code:
    <html>
    <head>
    <style type="text/css">
    #bar {visibility:hidden;}
    </style>
    <script>
    function show(el, txt){
    	var elem = document.getElementById(el);
    	elem.style.visibility = (txt == 'other') ? 'visible' : 'hidden';
    	}
    </script>
    </head>
    <body>
    <form method="POST">
      <select size="1" name="thename" class="asdf" onChange="show('bar', this.options[this.selectedIndex].firstChild.nodeValue)">
      <option selected>--- Choose One ---</option>
      <option>choice 1</option>
      <option>choice 2</option>  
      <option>other</option>
      </select><span id="bar"><input type="text"></span>
      <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
    </form>
    </body>
    </html>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Phil fillup07's Avatar
    Join Date
    May 2002
    Location
    Jacksonville, FL
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot!

    I guess what I'll end up doing is giving the option and text box fields different names. Then when the form is submitted if the value of the option is "Other" than I'll pull the value of the text box.


Bookmarks

Posting Permissions

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