views:

59

answers:

2

I have this code:

<select name="team[]" size="8" multiple="multiple">$team</select>

It lists for example players in that team, I want when user clicks on player it creates a new row where I can input basic info about player which I will add to database via php.

A: 

If I understand this question correctly, this is more about how you design your table and write your php than the HTML or the jQuery.

If you have a table like this:

table players:
player_id  int
first_name varchar(30)
last_name  varchar(60)

And another table like this:

table game_player_info:
id          int
player_id   int
goals       int
assists     int
penalties   int
notes       varchar(256)

Then you could pull the players out and populate the combo box. The HTML you would generate would be something like this:

<select name="player">
    <option value="{put player_id here}">{put player name here}</option>
    <option value="{put player_id here}">{put player name here}</option>
    <option value="{put player_id here}">{put player name here}</option>
</select>

<input type="text" name="goals"/>
<input type="text" name="assists"/>
<input type="text" name="penalties"/>
<textarea name="notes" rows="2" cols="20"></textarea>

Then, when you submit, you could do a sql call with a query something like this (you would want to check for errors and sql injection, but this is a simple example):

insert into game_player_info (player_id, goals, assists, penalties, notes) 
  values ($_POST['player'], $_POST['goals'], $_POST['assists'], 
  $_POST['penalties'], $_POST['notes'])

Hope this helps. If this does not answer your question, be sure to post more information for clarity.

coding_hero
A: 

something like this I suppose and just call based on an id or something for the player.

$(document).ready(function(){

$("a").click(function(event){
    $("<input>", {

     id: "playerName",
     type: "text",
     value: "playerName"    

    }).appendTo('form');
});

});

jeremiah