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:
- <script type="text/javascript" charset="utf-8">
- $(document).ready(function(){
- $("#adventure").change(function(){
- var value = $(this).val();
- console.log(value);
-
- $.ajax({
- type : "GET",
- url : 'new_loot.json.php',
- data : {
- adventure : value
- },
- success : function(data){
- $('#loot').html(data);
- }
- })
- });
- });
- </script>
- <?php
- echo ' <tr>';
- echo ' <td>';
-
- $sql = "SELECT * FROM adventures_adventurenames ORDER BY adventure ASC";
- $query = mysql_query($sql)or die(mysql_error());
- echo '<select name="adventure" id="adventure" >';
- echo ' <option value="">Choose adventure</option>';
- while($object = mysql_fetch_object ($query)){
- echo '<option value="'.$object->id.'">'.$object->adventure.'</option>';
- }
- echo '</select>';
-
- echo ' </td>';
- echo ' </tr>';
- echo ' <tr>';
- echo ' <td>';
- echo ' <div class="input_fields_wrap">';
- echo ' <button class="btnlite">Add loot item</button><br>';
- echo ' <div>';
- echo ' Loot Item <select name="loot[]" id="loot">';
- echo ' <option value="">--</option>';
- echo ' </select>';
- echo ' </div>';
- echo ' </div>';
- echo ' </td>';
- echo ' </tr>';
- ?>
new_loot.json.php
- <?php
- include_once "config.php";
- $db_json = mysql_connect($dbhost, $dbuser, $dbpasswd) OR die("Unable to connect to the database");
- $selected = mysql_select_db($dbname, $db_json) OR die("can not select the database ".$db_json);
- $adventure = mysql_real_escape_string($_GET['adventure']);
-
- $sql = "
- SELECT
- adventures_loot_options.id, adventures_loot_options.loot
- FROM
- adventures_loot_options,
- adventures_adventurenames,
- adventures_adventurename_loot
- WHERE
- adventures_adventurenames.id = ".$adventure." AND
- adventures_adventurenames.id = adventures_adventurename_loot.adventure_id AND
- adventures_loot_options.id = adventures_adventurename_loot.id
- ORDER BY adventures_loot_options.loot ASC";
- $query = mysql_query($sql);
- while($object = mysql_fetch_object ($query)){
- echo '<option value="'.$object->id.'">'.$object->loot.'</option>';
- }
- ?>