Jump to content

How to take user's input


Recommended Posts

  • 2 months later...

Of course.


Create an input box in your HTML:


<input type="text" name="fname" id="idofelement">


Then whenever you want to add the text to the game from the text in the input (ideally after a form submit event), you would do something like this:

function addText() {var element = document.getElementById('idofelement');var inputText = element.value;var text = game.add.text(0,0,inputText); text.addColor('#ffff00', 0);}
Heck you could even add the onChange event on the input element itself:
<input type="text" name="fname" id="idofelement" onchange="addText()">
or if you are using jQuery:
$('#idofelement').on('change',function() {addText()}); 
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...