/    Sign up×
Community /Pin to ProfileBookmark

introduction and a question…

Hi Everyone,

Just found the site. Right now, I’m a serious web newbie. But once I get
more up to speed on things, I’m looking forward to contibuting as much as
possible. I’ve been developing applications in Lotus Notes for the last 7
years, and have recently started developing for the web. As such, I’ve been
using JavaScript a bit, but I’m sure I’m gonna have some questions.

Like this one… ?

I have a form with separate fields for month day and year. If the user
enters 4 in the month or day field, I need them to autofill with a zero
(ie. 04). What’s the easiest/best way to do this in JS?

Thanks in advance…

Steve

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallApr 26.2006 — Assuming your form is named "myform" and the input field for the day is named "day" then calling the following code would insert the leading zero if required.

var day = parseInt(myform.day.value);
myform.day.value = (day < 10) ? '0'+day : day;
Copy linkTweet thisAlerts:
@stevemtnoauthorApr 26.2006 — Worked perfectly!!
Copy linkTweet thisAlerts:
@stevemtnoauthorApr 27.2006 — Hi Stephen,

Well, the users like the autofill so much, they came up with an couple more things for their 'want list':

  • 1. Ensure that the month entered is valid (01 - 12)

  • 2. Ensure that the day entered is valid for the month


  • Is there an easy way to do this?

    Thanks!

    Steve
    ×

    Success!

    Help @stevemtno spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...