0

I have a text field which is getting values from some process. I mean the user is not giving any input to this text field directly! Now my problem is that I want the value of that text field immediately after it changes. I tried

oninput and onchange

Here is the bin of what I have tried. Both events want to focus of that area please tell me is there any way to achieve this

Chris
  • 3,113
  • 26
  • 33
Null
  • 154
  • 1
  • 14

2 Answers2

7

As Kevin B suggested, trigger the event manually from the process that changes 'a'.

Essentially, on button click:

var a = document.getElementById('a');
a.value = value;
a.onchange();

A jQuery solution is here: http://jsbin.com/vozilevu/2

$('#my-button').click(function() {
    $('#a').val('a').change();
});
Clint Powell
  • 2,368
  • 2
  • 16
  • 19
0

If you really want to trigger a change event each time a character is entered, you can use something like this:

<input type="text" id="a" onkeyup="alert( document.getElementById('a').value )">
szr
  • 139
  • 10
  • 2
    This will not work for his situation: the button's `onclick` event is changing the value. The idea is he wants a programmatic change of value, not user input. – Clint Powell Feb 19 '14 at 15:33