user9824396
user9824396

Reputation:

add text to a-frame window from a form

How to add text from a form in the a-frame window

$("#text1").click(function(e){
	    var x = document.getElementById("fname").value;
        //document.write(x);
        document.getElementById("output").innerText = x;
        return false;   
	  });
<form name="myForm" href="" onsubmit="text" >
  id: <input type="number" value="text" name="fname" id="fname"><br><br>
  <input type="submit" value="Отправить">
</form>

<a-entity text="output" value="output"></a-entity>

Upvotes: 0

Views: 889

Answers (2)

brianpeiris
brianpeiris

Reputation: 10795

Use setAttribute to change the value of the text component on the entity.

There were also some other problems with your code that I've fixed below.

$("#text1").click(function(e) {
  var x = document.getElementById("fname").value;
  document.getElementById("output").setAttribute("text", "value", x);
  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="text">
  id: <input type="number" value="text" name="fname" id="fname"><br><br>
  <input id="text1" type="submit" value="Отправить">
</form>

<a-scene background="color: black">
  <a-entity id="output" text="value: output; align: center;" position="0 1.6 -0.5"></a-entity>
</a-scene>

Upvotes: 1

Mike Che
Mike Che

Reputation: 20

To access your a-entity element by ID, I suppose, this element must have ID setted <a-entity id="output"></a-entity> A-FRAME docs

Upvotes: 0

Related Questions