samuel toh samuel toh - 3 months ago 10
HTML Question

How to use 'on change' event on an input type hidden?

Demo and full code is like this :

http://jsfiddle.net/9R4cV/685/

I using like this :

$('#customer').on('change', function() {
$('#customer_copy').val($(this).val());
});


But it's not working

Any solution to solve my problem?

Answer
  1. You need to trigger .change() (or .trigger('change')) on input value changes, otherwise programatically changes are not triggering events.
  2. The id of your input is #customer not #customer_name.

$( "#tags" ).autocomplete({
    source: aTags,
    select: function(event, ui) {
        $("#customer").val(ui.item.label).change();
    }
});

$('#customer').on('change', function() {
    $('#customer_copy').val($(this).val());
});

Working example.

Comments