Search code examples
javascriptjqueryhtmlkineticjs

Set HTML input value using Kinetic.js


I want to set the value of an HTML input box when the user clicks, usign Kinetic.js.

This is the input box:

<input type="text" id="text_box">

and this is the method

stage.on('mousedown touchstart', function(evt) {
var shape = evt.targetNode;
if (shape) {
  if (shape.getFill() == 'green') { 
    // this is where the text box value should be changed.
    // I tried this:
    $("#text_box").val("hello");
  }     
}
  });

It doesn't seem to work.

How can I do this?


Solution

  • This should target the text box in your DOM.

    document.getElementById("text_box").setAttribute("value","hello");
    

    or

    document.getElementById("text_box").value = "hello";