How can I dynamically add/remove textbox (not clearing the data of textbox) and corresponding delete button on corresponding delete button click event through javascript?
NOTE:There is separate button for every dynamically created textbox.
Below is my javascript function. I’m using jQuery 1.3.2
function addOption()
{
var d=document.getElementById("yash");
d.innerHTML+="<input type='text' id='mytextbox' name='textbox' class='form-field medium' >";
d.innerHTML+="<input type='button' id='mybutton' name='del'>";
$("#mybutton").click(function () {
$("#mytextbox").remove();
$(this).remove();
});
d.innerHTML+="<br/>";
}
I made a very simple example for you: http://jsfiddle.net/BHdhw/
You can change it to suite your needs, here is the code:
HTML
Jquery
NOTE : When working with dynamic HTML, always use
.liveto bind your eventsUPDATE [Retrieving all values]
Link example how to retrieve values: http://jsfiddle.net/BHdhw/1/
Added HTML
Added Jquery