There is a button to add new forms, how to add text to the iframe
The first form adds text to the scene. However, the following forms, which are created at the click of a button, do not display the text How to combine two codes? File reference https://jsfiddle.net/Nickpo/q8jc1dgL/10/
$(document).ready(function() {
var max_fields = 10;
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><textarea type="text" value="text" name="fname" id="fname" cols="20" rows="3"></textarea></p><input id="text1" type="submit" value="Отправить"></div>'); //add input box
}
else
{
alert('You Reached the limits')
}
});
$(wrapper).on("click",".delete", function(e){
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
$("#text1").click(function(e) {
var wrapper = document.getElementById("text-container");
var position = new THREE.Vector3(wrapper.children.length * -1.1, 0, 0);
var newText = document.createElement('a-entity')
newText.setAttribute('position', position)
newText.setAttribute("text", {
"color": "white",
"align": "center",
"value": document.querySelector('#fname').value
})
wrapper.appendChild(newText)
return false
});
form {
position: absolute;
z-index: 1;
background: white;
padding: 1em;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<form name="myForm" href="" onsubmit="text1" height="440">
<textarea type="text" value="text" name="fname" id="fname" cols="20" rows="3"></textarea></p>
<input id="text1" type="submit" value="Отправить">
<div class="container1">
<button class="add_form_field">Add New Field <span style="font-size:4px; font-weight:bold;">+ </span></button>
<div><input type="text" name="mytext[]"></div>
</div>
</form>
<div class="container1">
<button class="add_form_field">Add New Field <span style="font-size:4px; font-weight:bold;">+ </span></button>
<div><input type="text" name="mytext[]"></div>
</div>
<a-scene background="color: black">
<a-entity id='text-container' position="0 1.6 -0.5">
<a-entity id="output" text="value: output; align: center;" position="0 0 0"></a-entity>
</a-entity>
</a-scene>