3

First of all check live example . There is a mask for dates on text box. Also there is a jQueryUI datepicker. They are working very well but when i choose a date with datepicker, text box's mask is disappearing. I want to keep it. Any ideas?

4
  • It works fine for me, Google Chrome on Windows 7. The underlining (mask effect) is lost when a date is entered, but that is normal. Unless you want to keep the underlining? Commented Sep 19, 2011 at 23:05
  • I want to keep them . Actually i want to turn it to (for example) 2011-09-19 00:00 . So visitor will be noticed, there is a time (00:00) and it can be changed. Commented Sep 19, 2011 at 23:07
  • The problem is that the underscore can't exist in the same place as the letter. Unless there is a way to style each individual letter with underlining. Not sure about that Commented Sep 19, 2011 at 23:10
  • No you missunderstood. I don't want to style each letter with an underscore. Commented Sep 19, 2011 at 23:13

1 Answer 1

3

I used this post. To create this fiddle.

You can adjust the javascript to default to 00:00 if you don't want the current time as the default.

date_obj = new Date();
date_obj_hours = date_obj.getHours();
date_obj_mins = date_obj.getMinutes();

if (date_obj_mins < 10) { date_obj_mins = "0" + date_obj_mins; }

if (date_obj_hours < 10) {date_obj_hours = "0" + date_obj_hours;}

date_obj_time = "'"+date_obj_hours+":"+date_obj_mins+"'";

$( ".datepicker" ).datepicker({ dateFormat: 'yy-mm-dd ' + date_obj_time });
$(".datepicker").mask("9999-99-99 99:99");

Thought I would add that this could be shortened to:

date_obj = new Date();
date_obj_hours = date_obj.getHours() < 10 ? "0" + date_obj.getHours() : date_obj.getHours();
date_obj_mins = date_obj.getMinutes() < 10 ? "0" + date_obj.getMinutes() : date_obj.getMinutes();

date_obj_time = "'" + date_obj_hours + ":" + date_obj_mins + "'";

$(".datepicker").datepicker({ dateFormat: 'yy-mm-dd ' + date_obj_time });
$(".datepicker").mask("9999-99-99 99:99");

fiddle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.