I have been trying to create dynamic textboxes on button click for each row generated from a database. But on click of add(+) button, the boxes are getting appended after all the rows of the db, instead of where I click after each row. Here is what I tried so far.
//Jquery function
$('#f2 .add-box').click(function(){
var box_html = $('<p class="text-box"><label for="box">Subtask</label> <a href="#" class="remove-box btn-sm btn-primary btn-remove"><span class="glyphicon glyphicon-remove"></span></a> <input type="text" name="boxes[]" class="form-control" value=""> </p>');
box_html.hide();
$('#f2 p.text-box').append(box_html);
box_html.fadeIn('slow');
return false;
});
//php code
while($row =mysqli_fetch_array($res))
{
echo "<div class='rowDiv' id='" . $row['id'] ."' contenteditable='true'>" . $row['desc'] . "</div>";
echo " <p class='text-box'> <a class='add-box' href='#' rel='" . $row['id'] ."' ><span class='glyphicon glyphicon-plus'></span></a></p><br/>";
}
Any help is much much appreciated.
to div tags, gave them unique ids too. But when i click on add button, text box gets created after echoing all rows of db, not after each row.
– apoo Dec 30 '15 at 10:40