-1

I have 2 text field look like this :

HTML :

<input type="text" id="input1" onchange="doSomething();" disabled/>
<input type="text" id="input2"/>

JavaScript :

function doSomething(){
 alert('Changed!');
}

$("#input2").change(function(){
 $("#input1").val(this.val());
});

My Problem are :

When i change value of input2 , i hope input1 will do doSomething cause the value has changed. But my problem, it's not wokring for me right now. Can anyone explain why and how to fix it?

Mr. Mike
  • 453
  • 5
  • 23

1 Answers1

1

You should use $(this).val() or this.value. val() is jquery method so you need to use jquery $(this) selector.

$("#input2").keyup(function(){
 $("#input1").val($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="input1"  disabled/>
<input type="text" id="input2"/>
Nenad Vracar
  • 118,580
  • 15
  • 151
  • 176