Use .val()
to set input values:
$('#two').val(result);
Often, setting element attributes won't update more than once. You need to update their properties instead using .prop
or using functions intended for the purpose, like .val()
.
Domanda
I'm experiencing this trouble with jQuery and attr() function.
Take a look:
one <input id='one' type="text"><br>
two <input id='two' type="text">
<script>
$('#one').on('input',
function(){
var result = 'test'
$('#two').attr('value',result);
}
);
</script>
This is the trouble:
P.S. See the live code here http://jsfiddle.net/5XQJj/4/
Soluzione
Use .val()
to set input values:
$('#two').val(result);
Often, setting element attributes won't update more than once. You need to update their properties instead using .prop
or using functions intended for the purpose, like .val()
.
Altri suggerimenti
Try .prop()
$('#one').on('input', function () {
var result = 'test'
$('#two').prop('value', result);
});
Read .prop() vs .attr()
$('#two').val(result);
you should use .val()
rather than .attr
or .prop
updated JSfiddle: http://jsfiddle.net/5XQJj/6/
$('#one').on('change', function () {
var result = 'test'
$('#two').val(result);
});