Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Javascript date validation - combining month, day and year

Posted on 2007-07-19
Medium Priority
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
  • 3

Author Comment

ID: 19527795
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

ID: 19527996
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

ID: 19528011
Thanks but what if they are select boxes?
LVL 14

Accepted Solution

steveberzins earned 2000 total points
ID: 19528573
.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 easy...so do it like above.
<select name="StartMonth">

Author Comment

ID: 19528636

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…
Suggested Courses

571 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