I have 2 tables in my database call groups and players i am trying to select the group first and then the players show up in another listbox.
DB:
Groups
+-----+---------------+
| id | Name |
+-----+---------------+
| 1 | Red Group |
| 2 | Blue Group |
| 3 | Yellow Group |
+-----+---------------+
Players
+-----+-----------+------------+
| id | name | group_id |
+-----+-----------+------------+
| 1 | User1 | 1 |
| 2 | User2 | 3 |
| 3 | User3 | 2 |
| 4 | User4 | 3 |
| 5 | User5 | 1 |
+-----+-----------+------------+
output group's records at server end, into a select, then ,as vasim said, use jquery's change (http://api.jquery.com/change/) to fire an ajax call which will populate palyers select by the group id.
$('#group').change(function()
{
$.ajax(
{
url: 'url_to_server_script',
data: 'group='+$('#group').val(),
success: function(){/* populate here your players select*/}
});
});
more info about jquery's ajax at http://api.jquery.com/jQuery.ajax/ . depending on what your server script willr eturn you'll have to specify the ajax property datatype (json,xml,...)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.