I am trying to make a user selects insert data into the text area and also be able to duplicate the text area by clickin a button, which then will create a duplicate empty text area . the problem i am having at the moment is that once the user clone the textarea, it duplicate the text area with the data from the previous text area. Struggling a bit with the Jquery, would appreciate some helps thank you in advance.
<div id ="specdiv ">
<fieldset class="fieldset">
<legend class="legend">Question Specification</legend>
<div class="editor-label">
@Html.LabelFor(model => model.OfferedAnswer)
</div>
<div class ="answerchoice1" id="copybox">
<div class="editor-field" >
@Html.TextAreaFor(model => model.OfferedAnswer.AnswerText)
</div>
</div>
</fieldset>
</div>
Jquery code:
$("#dialog-message").hide();
$(document).ready(function () {
$('button').click(function () {
//$('.answerchoice1').before($('.answerchoice1').clone())
if ($('.editor-field').length >= 10) {
// alert('No more than 6!');
// $("<div title='Answers Limit has been reached'> You cannot add more anwer choice if you would like to add more please consider to create a new question. Thank you </div>").dialog(
// ).css('border','2px solid red');
$("#dialog-message").dialog({
modal: true,
draggable: true,
resizable: false,
position: ['center', 'bottom'],
show: 'blind',
hide: 'blind',
width: 400,
dialogClass: 'ui-dialog-osx',
buttons: {
"I've read and understand this": function () {
$(this).dialog("close");
}
}
});
return false;
}
var $target = $('.answerchoice1').find('div.editor-field:first');
$target.clone().appendTo('.answerchoice1').find("editor-field").val("");
$target.find('.answerchoice1').val("");
$target.insertAfter(".div.editor-field:last")
})
});