AJAX - When drop down is selected automatically create ... something

Discussion in 'Programming' started by PET, Sep 8, 2010.

  1. #1
    Hello,

    I'm having troubles searching for this because I don't know what to search for in order to read.

    I will have a drop down with some options. Let's say 1,2,3,4.

    If I select 1 I want to automatically add a number of "textfields" to the form.
    If I select 2, I want more textfields to be automatically added to the forum.

    The interesting part is that I will have 2 forms that will influence the textfields I want to create.

    I'm doing a tournament script. So I will have a drop down that will say:
    Numer of Players: 4,8,16,32,64

    After that I have a drop down that will say:
    1v1, 2v2, 3v3, 4v4

    So if I select 16 players 1v1 I want 16 textfields to be automatically shown.
    If I select 16 players 2v2 I want 32 textfields to be automatically shown.

    Etc.

    Any idea on how to do this in Ajax?

    Thank you for your time.
     
    PET, Sep 8, 2010 IP
  2. AntelopeSalad

    AntelopeSalad Peon

    Messages:
    85
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It has nothing to do with ajax really. Get the functionality working with whatever server side language you're working with, then add the ajax effect.

    All you really have to do is setup the option values for your select boxes in such a way that you can multiply them.

    1. The option value for the number of players is set to the actual number of players.
    2. The option value for the format (1v1, 2v2, etc.) is set to a number that's relevant to the selection (1 = 1v1 , 2 = 2v2 , 3 = 3v3, etc.).

    Then multiply the values to figure out how many text boxes you need to spawn. In your example if someone were to fill out the form you would get 16 and 2 and 16*2 = 32.
     
    AntelopeSalad, Sep 8, 2010 IP
  3. PET

    PET Member

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Yea but how do I dinamically show the text boxes? I know that I will do the calculations in PHP but I don't know how to show them. I'm also using smarty so I guess the "foreach" will be done in Smarty.

    I was thinking I need to get the variable. 1v1 x number of players or 2v2 x number of players then do a FOR for that variable's number.
     
    PET, Sep 8, 2010 IP
  4. AntelopeSalad

    AntelopeSalad Peon

    Messages:
    85
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Google for .ajax with jQuery.
     
    AntelopeSalad, Sep 8, 2010 IP