javascripthtmleclipse-jee

How to call a JavaScript function with onchange Event if my input value changed by Java Method


I am getting a value in my input this way:

<input style="width:200px; display:none;" readonly="" type="text" id="abc" placeholder="30.30" value="#{position.layers}"></input>

How can I call the JavaScript function if a value changed.

function callme() {
    alert("ok");    
}

If I type in the value by myself, the method is called, but if the value is changed by "#{position.layers}" the function is not called.

 <input style="width:200px; display:none;" readonly="" type="text" id="abc" placeholder="30.30" value="#{position.layers}" onchange="callme()"></input>

Solution

  • You cannot trigger change event directly if you are passing value by using other mean

     var element = document.getElementById('abc');
     var event = new Event('change');
     element.dispatchEvent(event);
    

    Instead you have to create a change event and try to invoke your change event , add above code after you are changing value of input type rest of your code is good to go nothing to change.