I need to autofill an input field with the values of another input fields. So far I have this:
JavaScript
x
10
10
1
$("#field1, #field2").keyup(function(){
2
$("#result").val(this.value);
3
});
4
5
<input type="text" id="field1" name="field1" value="" >
6
<input type="text" id="field2" name="field2" value="" >
7
8
//* to be filled with the values of the inputs above *//
9
<input type="text" id="result" name="resut" value="">
10
Advertisement
Answer
What about
JavaScript
1
8
1
$("#field1, #field2").keyup(function(){
2
update();
3
});
4
5
function update() {
6
$("#result").val($('#field1').val() + " " + $('#field2').val());
7
}
8
JavaScript
1
7
1
$("#field1, #field2").keyup(function(){
2
update();
3
});
4
5
function update() {
6
$("#result").val($('#field1').val() + " " + $('#field2').val());
7
}
JavaScript
1
5
1
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
2
<input type="text" id="field1" name="field1" value="" >
3
<input type="text" id="field2" name="field2" value="" >
4
<br>
5
<input type="text" id="result" name="resut" value="">