'Dynamic text boxes to textbox
I am attempting to create dynamic text boxes then pull that info into a text box so i can copy it. I got the code to add the boxes but i dont know how to get the information from the boxes to compile and go into my AddRESS text box.
HTML
<div class="row">
<div class="cell">
<button class="cell add_form_field" style="color: black;">Add New Field
<span style="font-size:16px; font-weight:bold; color: black;">+ </span>
</button>
</div>
<div class="cell container1">
<div><input type="text" name="myAdd[]"></div>
<div class="container2">
<div><input type="text" name="myMAC[]"></div>
</div>
</div>
<textarea id="AddRESS" rows="10" cols="49" style="overflow: auto; width: 500px;font-size: 10px;"></textarea></div>
</div>
</div>
JavaScript
$(document).ready(function() {var max_fields = 20;var wrapper = $(".container1");var add_button = $(".add_form_field");var x = 1;
$(add_button).click(function(e) {
e.preventDefault();
if (x < max_fields) {
x++;
$(wrapper).append('<div><input type="text" name="myAdd[]"/><a href="#" class="delete">Delete</a></div>'); //add input box
} else {
alert('You Reached the limits')
}
});
$(wrapper).on("click", ".delete", function(e) {
e.preventDefault();
$(this).parent('div').remove();
x--;
})});$(document).ready(function() {var max_fields = 20;var wrapper = $(".container2");var add_button = $(".add_form_field");var x = 1;
$(add_button).click(function(e) {
e.preventDefault();
if (x < max_fields) {
x++;
$(wrapper).append('<div><input type="text" name="myMAC[]"/><a href="#" class="delete">Delete</a></div>'); //add input box
} else {
alert('You Reached the limits')
}
});
$(wrapper).on("click", ".delete", function(e) {
e.preventDefault();
$(this).parent('div').remove();
x--;
})});
I have tried this
var values = $("form [name='myAdd[]']").map(function(){return $(this).val();}).get()document.getElementById("AddRESS").innerHTML = values;
and several other things but I only get undefined errors in my AddRESS box.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
