chain select -> multiply 2nd select

chain select -> multiply 2nd select

Hi,

I have 2 chained selectboxes, both filled fromout a database. This is working correctly.
But now I want to add multiple instances of the 2nd box after a button push (or to remove one if needed) with a max of 15 instances.
Can anyone help me with this?

My code op the php-page:
  1. <script type="text/javascript" charset="utf-8">
  2. $(document).ready(function(){
  3. $("#adventure").change(function(){
  4. var value = $(this).val();
  5. console.log(value);

  6. $.ajax({
  7. type : "GET",
  8. url : 'new_loot.json.php',
  9. data : {
  10. adventure : value
  11. },
  12. success : function(data){
  13. $('#loot').html(data);
  14. }
  15. })
  16. });
  17. });
  18. </script>
  19. <?php
  20. echo ' <tr>';
  21. echo ' <td>';

  22. $sql = "SELECT * FROM adventures_adventurenames ORDER BY adventure ASC";
  23. $query = mysql_query($sql)or die(mysql_error());
  24. echo '<select name="adventure" id="adventure" >';
  25. echo ' <option value="">Choose adventure</option>';
  26. while($object = mysql_fetch_object ($query)){
  27. echo '<option value="'.$object->id.'">'.$object->adventure.'</option>';
  28. }
  29. echo '</select>';

  30. echo ' </td>';
  31. echo ' </tr>';
  32. echo ' <tr>';
  33. echo ' <td>';
  34. echo ' <div class="input_fields_wrap">';
  35. echo ' <button class="btnlite">Add loot item</button><br>';
  36. echo ' <div>';
  37. echo ' Loot Item <select name="loot[]" id="loot">';
  38. echo ' <option value="">--</option>';
  39. echo ' </select>';
  40. echo ' </div>';
  41. echo ' </div>';
  42. echo ' </td>';
  43. echo ' </tr>';
  44. ?>


new_loot.json.php
  1. <?php
  2. include_once "config.php";
  3. $db_json = mysql_connect($dbhost, $dbuser, $dbpasswd) OR die("Unable to connect to the database");
  4. $selected = mysql_select_db($dbname, $db_json) OR die("can not select the database ".$db_json);
  5. $adventure = mysql_real_escape_string($_GET['adventure']);

  6. $sql = "
  7. SELECT 
  8. adventures_loot_options.id, adventures_loot_options.loot
  9. FROM 
  10. adventures_loot_options, 
  11. adventures_adventurenames,
  12. adventures_adventurename_loot
  13. WHERE
  14. adventures_adventurenames.id = ".$adventure." AND
  15. adventures_adventurenames.id = adventures_adventurename_loot.adventure_id AND
  16. adventures_loot_options.id = adventures_adventurename_loot.id
  17. ORDER BY adventures_loot_options.loot ASC";
  18. $query = mysql_query($sql);
  19. while($object = mysql_fetch_object ($query)){
  20. echo '<option value="'.$object->id.'">'.$object->loot.'</option>';
  21. }
  22. ?>