[jQuery] How to simulate a human-triggered event?

[jQuery] How to simulate a human-triggered event?


Hi, I'm trying to change the value of an input field (target) which
depends on another input (source). It works well when I manually
change the source value. But if I changed the source value with
another button, the target value remains the same. Here's the code...
$(document).ready(function() {
    $('input#change').click(function() {
        $('input#source').attr('value', 'This is the value changed by a
button');
    });
    $('input#source').change(function() {
        $('input#target').attr('value', $('input#source').attr('value'));
    });
});

Source: <input type="text" name="target" id="source" size="60"
value="" /> <input type="button" id="change" value="change source
value" />


Target: <input type="text" name="target" id="target" size="60"
value="This is the original value, type something in source to
change" />


So how could the target input detect if there's a change within the
source input without manually changing it's value? Thanks