Javascript date validation - combining month, day and year

Posted on 2007-07-19
Last Modified: 2008-03-03

How would I add 3 form fields together to create one variable in javascript? I have 3 form fields: StartMonth, StartDay, StartYear and I want to create a validation in javascript but first need to combine these fields into one to create a date like: 07/19/2007.

This is the function that I need to change:

function ValidateForm(){
      var dt=document.Event.txtDate
      if (isDate(dt.value)==false){
            return false
    return true

But instead of:
var dt=document.Event.txtDate

I need to comnine 3 formfields...

as "var dt" fomatted like 07/19/2007.

I know this is simple but I don't know javascript very well and I know there is a guru out there who can help very quickly. Thanks in advance.
Question by:ChristinaPupo

    Author Comment

    I have this but it's not working

    var dtmonth=document.Event.StartMonth;
    var dtday=document.Event.StartDay;
    var dtyear=document.Event.StartYear;
    var dt= (dtmonth + "/" + dtday + "/" + dtyear);

    Can anyone help?
    LVL 25

    Expert Comment

    hi Christina,
    you need add also ".value" to get the value

    var dtmonth=document.Event.StartMonth.value;
    var dtday=document.Event.StartDay.value;
    var dtyear=document.Event.StartYear.value;
    var dt= (dtmonth + "/" + dtday + "/" + dtyear);

    Author Comment

    Thanks but what if they are select boxes?
    LVL 14

    Accepted Solution

    .value will still work... as long as the option value is there.

    this will work fine:
    <select name="StartMonth">
      <option value="01">01</option>
      <option value="02">02</option>
      <option value="03">03</option>

    this would work, but .value wouldn't, you'd have to get the selected items text, not quite as do it like above.
    <select name="StartMonth">

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Android App Development

    This course will involve creating widgets, customize list view, grid view, spinners, etc. Creating applications using audio, video, and SQLite database. Ending with publication on Google Play.

    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (, typical array handling might look like this: (CODE) B…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now