Skip to content

Instantly share code, notes, and snippets.

@PatrickatPaperlessPCS
Created January 23, 2016 19:10
Show Gist options
  • Save PatrickatPaperlessPCS/2e80d553e767429bfe7b to your computer and use it in GitHub Desktop.
Save PatrickatPaperlessPCS/2e80d553e767429bfe7b to your computer and use it in GitHub Desktop.
<script type="text/javascript">
$(document).ready(function(){
var counter = 2;
$(document).click(function () {
if(counter>10){
alert("Only 10 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.after().html('<input type="text" name="textbox' + counter +
'" id="textbox' + counter + '" value="" >');
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter++;
});
$("#removeButton").click(function () {
if(counter==1){
alert("No more textbox to remove");
return false;
}
counter--;
$("#TextBoxDiv" + counter).remove();
});
$("#getButtonValue").click(function () {
var msg = '';
for(i=1; i<counter; i++){
msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();
}
alert(msg);
});
});
</script>
</head><body>
<div id='TextBoxesGroup'>
<div id="TextBoxDiv1">
<input type='textbox' id='text1' name="document[text1]" >
</div>
</div>
<input type='button' value='Remove Button' id='removeButton'>
<input type='button' value='Get TextBox Value' id='getButtonValue'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment