show hide text box

Discussion in 'JavaScript' started by 3.5supersonic, Nov 12, 2010.

  1. #1
    Hi

    Im looking for a way to show hide text box on select option change

    
    
    <select name="letter_type" id="lt">
                        <option value="Registered">Registered</option>
                        <option selected="selected" value="Unregistered">Unregistered</option></select>
                        <input name="textfield7" id="regty" type="text" accesskey="1" tabindex="1" size="20" />
    
    PHP:
    i wana show that text box if user select "Registered" from select option.

    any help would be great



    sorry for language errors.

    Thanks
     
    3.5supersonic, Nov 12, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    And where is the hide box? Is it <input name="textfield7" id="regty" type="text" accesskey="1" tabindex="1" size="20" />? If yes, is it hide by CSS?
     
    s_ruben, Nov 12, 2010 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    I think this is what you want to do:
    
        <select name="letter_type" id="lt">
            <option value="Registered">Registered</option>
            <option selected="selected" value="Unregistered">Unregistered</option>
        </select>
        <input name="textfield7" id="regty" type="text" accesskey="1" tabindex="1" size="20" style="display: none; " />
        <script type="text/javascript">
            var sel = document.getElementById("lt");
            var inp = document.getElementById("regty");
            sel.onchange = function() {
                inp.style.display = (sel.value=="Registered")?"block":"none";
            }    
        </script>
    
    Code (markup):
     
    camjohnson95, Nov 12, 2010 IP