Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 1st, 2005, 05:30 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default JS validation on the drop-down menus

<script language="javascript">
// Date of Birth Validation             //
// Check if Infant < 2 Jahre Alt     //
// Check if Child < 12 Jahre Alt     //
Date.prototype.getDiff = function(date, interval){
  if (typeof date == "string"){
     date = new Date(date);
  if (isNaN(date) || !(date instanceof Date)){
     return NaN; 
  if (typeof interval == "undefined") interval = "ms"; 
  var diff = this - date; 
    case "s": 
        diff = diff/1000; break;
    case "n": 
        diff = diff/(1000*60); break;
       case "h": 
        diff = diff/(1000*60*60); break;
       case "d": 
        diff = diff/(1000*60*60*24); break;
    case "m": 
        diff = diff/(1000*60*60*24*30); break;
    case "y": 
        diff = diff/(1000*60*60*24*365); break;
  return Math.floor(diff);

function checkBirthday(obj) {
    if( !/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(obj.value) ) {
        alert( "Invalid date supplied - must be format DD/MM/YYYY" );

    var d = new Date();
    var d2 = new Date(RegExp.$3, RegExp.$2, RegExp.$1);

    var diff = d.getDiff(d2, "y")
    if( isNaN(diff) ) {
        alert( "Invalid date supplied" );
    else if( diff < 2 ) {
        alert( "This IS an INFANT \n they are younger that 2" );
        infant = true;
    else if( diff > 2 ) {
        alert( "This is NOT an INFANT \n they are older that 2" );
        infant = false;
        document.form.birthday.value = "";



<select name="date<%=k%>"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
For d = 1 to 31
    Response.write "<option value=" & d & ">" & d & "</option>"
<select name="month<%=k%>"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
For m = 1 to 12
    response.Write "<option value=" & m & ">" & MMtoMMM(m) & "</option>"
Dim three_years_ago
three_years_ago = year(date) - 3
<select name="year<%=k%>"
style="color: black; font: 7pt Verdana, Arial, Helvetica, sans-serif;">
For y = three_years_ago to year(date)
    Response.Write "<option value=" & y & ">" & y & "</option>"

<input type="text" name="birthday" size="5" style="font:7pt;" value="" maxLength="10"> 

<img src="images/confirm.gif" alt="Confirm" name="HoldFlights" width="80" height="15" border=0  id=submit1 title="The reservations will be confirmed now" onclick="javascript: checkBirthday(document.form.birthday);return confirmedok();document.body.style.cursor = 'wait';" onMouseOver='style.cursor="hand"'  value="Confirm">
I am having a problem with this code. I am looking to have JS validation on the drop-down menus like I said before.
I am trying to put the values of the drop-down menus into a textbox then validate it.
Although, i am experiancing problems. How can i do this? I am trying to check if the date of birth is MORE than two years ago
(i.e. if the infant is older than 2years old). If they are then dont submit the form and show pop-up (ALERT). Else, submit form to next page.

Ayrshire Minis - a Mini E-Community
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Announcement: Ch3, Dynamic Drop Down Menus richard.york BOOK: CSS Instant Results 0 November 14th, 2006 10:57 AM
adding values from drop down menus racey Classic ASP Basics 1 August 22nd, 2006 05:26 AM
Drop Down Menus in Tables danludlow Javascript How-To 0 April 8th, 2006 05:22 PM
change the value of two drop-down menus crmpicco Classic ASP Basics 3 March 28th, 2005 08:10 PM

All times are GMT -4. The time now is 09:18 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.