Display X Amount Corresponding with Dropdown Choice (Help!)

Discussion in 'Programming' started by mmelen, Dec 22, 2009.

  1. #1
    I need help. I am not sure what language this is... but I have seen it on many websites but can't find any examples now.

    Let me illustrate: There is a dropdown menu that has #'s: 1,2,3,4. And then depending on the number you choose, than there is X number of items displayed. In the example I saw, the dropdown asked the number of websites you own... and then it explains the appropriate number of textboxes to input each website separately.

    Can someone help me out... what is this called or do you have an example?

    Thanks in advance.
     
    mmelen, Dec 22, 2009 IP
  2. jedi.knight

    jedi.knight Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Easy to implement using JQuery. Do you need a code sample?
     
    jedi.knight, Dec 23, 2009 IP
  3. mmelen

    mmelen Well-Known Member

    Messages:
    1,526
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Yes, can you please show me a sample of this.
     
    mmelen, Dec 23, 2009 IP
  4. jedi.knight

    jedi.knight Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here is a very primitive one which demos it. You need to have jquery.js also in the same directory:

    
    <html>
     <head>
      <title>Dropdown demo</title>
      <script language="javascript" type="text/javascript" src="jquery.js"></script>
      <script language="javascript">
      <!--
    
    $(document).ready(function() {
        for (i = 1; i <= 10; i++)
            $('#num_sites').append('<option name="' + i + '">' + i + '</option>');
    });
    
    function set_textboxes()
    {
        var n = $('#num_sites').val();
    
        $('#sites').empty();
        for (i = 1; i <= n; i++)
            $('#sites').append('<tr><td>Site ' + i + '</td><td><input type="text" name="site' + i + '" /></td></tr>');
    }
    
      -->
      </script>
     </head>
     <body>
      <form>
    
       <select id="num_sites" name="num_sites" onchange="set_textboxes();">
        <option>Select...</option>
       </select>
       <table><tbody id="sites"><tr><th>#</th><th>URL</th></tbody></table>
      </form>
     </body>
    </html>
    
    Code (markup):
     
    jedi.knight, Dec 23, 2009 IP