-1

I have a javascript function that updates the result of a textbox dynamically, then that textbox executes based on that value.

  <script>
  function updatemykad(mykad) {
  $('#asd3').val(mykad);
  }
  </script>

The textbox loads on, on change, on paste. But it doesn't execute from the dynamically inputted value.

    $('input#asd3').bind('input propertychange', function(e) {
   console.log(this.value);
    var $q = $(this);
    if($q.val.length == 12){
    ....
Johan Fourie
  • 169
  • 12
  • 1
    You have to manually trigger handler or event, once you changed value dynamically – A. Wolff Nov 25 '15 at 11:22
  • 1
    you need to trigger the handle like this $('#asd3').val(mykad).trigger("change") – Anoop Joshi P Nov 25 '15 at 11:23
  • @AnoopJoshi I guess you meant `trigger("input")` :) But i'm sure OP get the idea – A. Wolff Nov 25 '15 at 11:24
  • @A.Wolff Thank you, that did the trick! :) – Johan Fourie Nov 25 '15 at 11:25
  • 1
    @A.Wolff trigger("change") also invoke the change event – Optimus Nov 25 '15 at 11:26
  • Possible duplicate of http://stackoverflow.com/questions/4672505/why-does-the-jquery-change-event-not-trigger-when-i-set-the-value-of-a-select-us http://stackoverflow.com/questions/3179385/val-doesnt-trigger-change-in-jquery http://stackoverflow.com/questions/6533087/jquery-detect-value-change-on-hidden-input-field Google before posting question.. – murli2308 Nov 25 '15 at 12:33

1 Answers1

0

You have to trigger change function when change value.

<script>
  function updatemykad(mykad) {
  $('#asd3').val(mykad);
  $('input#asd3').trigger("change");
  }
</script>
Atif Tariq
  • 2,650
  • 27
  • 34