Show/Hide TextBox when dropdown selected

Discussion in 'jQuery' started by Peoko, Jun 12, 2011.

  1. #1
    Hello,

    I have a dropdown select (option 1, option 2 and option 3), when i select one of the options i would like a textbox to appear with a label for that option.
    How can this be accomplished?
    Thank you.
     
    Peoko, Jun 12, 2011 IP
  2. daljit

    daljit Well-Known Member

    Messages:
    312
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #2
    This is possible using jquery to appear an text box when you select any option.
     
    daljit, Jun 15, 2011 IP
  3. ThemesAddict

    ThemesAddict Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #3
    jquery can help you out , try searching for jquery tabs or accordion , it will help you out in what you may require
     
    ThemesAddict, Jun 19, 2011 IP
  4. LeetPCUser

    LeetPCUser Peon

    Messages:
    711
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    CSS
    
    #message1,
    #message2 {
        display: none;
    }
    
    Code (markup):
    HTML
    
    <div id="message1">Option 1 is selected, woot!</div>
    <div id="message2">Option 1 is selected, woot!</div>
    
    <select name="dropdown" id="dropdown">
        <option value=""></option>
        <option value="1">1</option>
        <option value="2">2</option>
    </select>
    
    Code (markup):
    JQuery
    
    $(document).ready(function() {
        $('#dropdown').change(function() {
            dropdown = $('#dropdown').val();
    
            $('message1').hide();
            $('message2').hide();
    
            if (dropdown == '1')
            {
               $('message1').show();
            }
    
            if (dropdown == '2')
            {
               $('message2').show();
            }
        });
    });
    
    Code (markup):
     
    LeetPCUser, Jul 8, 2011 IP
  5. traihu

    traihu Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks you very much !
     
    traihu, Aug 3, 2011 IP
  6. hangcun

    hangcun Peon

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you very much for helping me finding the answer.I'll use it for my next magento themes
     
    hangcun, Aug 21, 2011 IP