user3108268
user3108268

Reputation: 1083

jQuery: autofill input values with mouse click not keyboard

I'm using this solution https://stackoverflow.com/a/4932770/3108268

$("#EmailAddress").keyup(function(){
    $("#Username").val(this.value);
});

And it works fine when typing input values with a keyboard, it auto fills the selected field.

But it doesn't work when filling a field with a mouse click from calendar popup javascript plugin. The popup plugin gives the input classes hasDatepicker date-popup-init.

This is all inside Drupal 7, but I don't think it's relevant.

Here's an example, as you can see the time field is plain text and autofills below, because it is being filled with a keyboard while filling the date field with mouse click from calendar popup does not fill the field below it (but does if you force-type with keyboard).

enter image description here

Upvotes: 0

Views: 424

Answers (1)

Emre Kabaoglu
Emre Kabaoglu

Reputation: 13146

You could use change event;

$( "#EmailAddress" ).change(function() {
  $("#Username").val(this.value);
});

Upvotes: 1

Related Questions