javascript - Validating time entered into textbox -
i have textbox in user can enter time (eg: 01:00) , drop down box entering am/pm fields. (since am/pm field used, 12-hour time format used.)
the text box allows max entry of 5 chars (eg: 01:00).
- how can set 3rd char default colon
:
, user has enter time. - how check if time entered user numeric or not?.
- autocomplete feature: example, if user enters 1 automatically set 01:00
- javascript validations 12-hour format. eg: if user enters 13:00 should change 01:00
- how can append text box time values am/pm value selected in drop down box?.
- once values appended, automatically populate text box (text box 2) result. eg: 01:00 + pm should set 01:00p in new text box (text box 2).
any appreciated.
- better have textbox size , maxlength of 2 named "txthours", colon label (span tag) , textbox named "txtminutes". easier manage.
- instead of checking, have
onkeypress
code returns false when key pressed not number allowing digits. - best done in
onblur
event, if value less 10 add 0 in beginning. - pretty simple script, though not trivial - use
%
operator. - not sure mean? append where?
document.getelementbyid("textbox2").value = strappendedtext;
that's general idea, let me know if need implementing best give try first.
Comments
Post a Comment