1

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>
Ruslan
  • 6,090
  • 1
  • 21
  • 36
java programming
  • 125
  • 2
  • 11
  • 1
    why the java tag? – f1sh Feb 26 '19 at 15:50
  • onchange events will only trigger on user input. You need to call `callme()` manually when you change the value with code. So you need a different way to trigger the function. But since I have no idea how eclipse `#{position.layers}` changes the value attribute, I'm not sure which event you could hook onto without more context. – Shilly Feb 26 '19 at 15:53
  • I assume the Java tag is due to using eclipse-jee as the dev tool. – Shilly Feb 26 '19 at 15:55

2 Answers2

1

Easiest way is to check the value of position layers and when it equals the value you are looking for call your function. So something like this:

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

 function doNotCall(){
    alert("No Way");
    }

 if(position.layers == someValue){
      callme();
  }else{
      doNotCall();
  }
codeKracken
  • 127
  • 14
  • Thanks to everyone for the answers. I actually changed the solution what I wanted to do in the JavaScript function now i am doing it in Java and getting the value in return. – java programming Feb 26 '19 at 19:00
1

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.