Question

I have a button adding new row. But when I make a selectt for my new row is empty. I don't really know how to fill it like my original row.

JavaScript/jQuery Code:

var counter = 0;
var $newRow ; 
$(function(){
    $('#add_field').click(function(){
        counter += 1;
        $('#tache').append('<select id="tache' + counter + '" name="tache[]' + '" type="text"  />');
    });
});

Here an exemple of my original row how I fill my select.

<!-- tache  -->
<td>
    <span id="tache">
    <!-- dꣵt section combobox tache avec tool tip -->
    <label title="Selectdimanche">
        <select title="Selectdimanche" id="Selectdimanche" name="Selectdimanche">
        <?php
        $stmt->execute();
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            echo ' <option title="';
            echo $row['tacName'];
            echo '">';
            echo $row['tacId'];
            echo '</option>'."\n";
            $task = array();
         }
         ?>
         </select>
      </label>
     <!-- Fin section cobobox tache avec tool tip -->
    </span>
</td>

So How I fill my data for my new row?

Was it helpful?

Solution

You can copy options from first select like this:

var counter = 0;
$('#add_field').click(function()
{
  counter += 1;
  var select = $('<select id="tache' + counter + '" name="tache[]" type="text"  />');
  select.append($("#Selectdimanche option").clone());
  $("#tache").append(select);
});

example: jsFiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top