Bilal Akil
Bilal Akil

Reputation: 4755

JQuery event, text changed but NOT by keyboard - how to catch it?

Scenario: A humble text field, marked as readonly. When clicked a datepicker appears. When you click a date from the datepicker it populates that text field with something like: 10/05/2013.

Problem: I need to reformat the text from 10/05/2013 to Friday, May 10, 2013. To do this I need to catch when the value inside the text field is changed. This is where the problem begins. The typical events are:

My code looks something like:

$('input[type="text"]').datepicker('hide');
// That sets up the datepicker (as per a plugin) to pop up
// when I click the text box, working fine :D

$('input[type="text"]').live('change keyup paste input', function() {
    // Trying everything out of desperation :/
    alert($(this).value());
});

Question: How can I catch when the text in this input field changes under in the scenario described?

Upvotes: 1

Views: 804

Answers (2)

billyonecan
billyonecan

Reputation: 20250

Why can't you just set the dateFormat?

$('input[type="text"]').datepicker({
    dateFormat: 'DD, M d, yy'   
});

Here's a fiddle

Upvotes: 1

Madthew
Madthew

Reputation: 686

Try it here:

http://jsfiddle.net/Madthew/9nw3f/

and follow this: http://api.jqueryui.com/datepicker/#option-dateFormat

in order to format your date.

If you leave 'hide' here:

$('input[type="text"]').datepicker('hide');

the calendar doesn't appear.

Upvotes: 0

Related Questions