1
I have the following script:
$(document).ready(function() {
var i = 0;
$("#add_row").click(function() {
if(i <= 5)
{
$('#addr' + i).html("<div><input type='text' name='cirurgia' value="+i+"></div>");
$('#input').append('<div id="addr' + (i + 1) + '">');
i++;
}
});
$("#delete_row").click(function()
{
if (i > 1)
{
$("#addr" + (i - 1)).html('');
i--;
}
});
});
When the user clicks on <div id="add_row">
, the script adds an input and if the user clicks <div id="delete_row">
, deletes the last added input.
So far the script is working correctly, but it happens that to add the 1° input
the user needs to double-click the "add_row" button. Then to add 2°, 3°, 4° and 5° inputs
just click 1 time, normally. Because this happens?
Simple HTML:
<input type="button" id="delete_row" value="deletar">
<input type="button" id="add_row" value="adicionar">
<br>
<div id="input">
</div>
Excellent reply Isac! It worked perfectly. Thank you very much. You are beast!
– D. Watson