Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 1st, 2005, 06:25 AM
Friend of Wrox
 
Join Date: Jan 2005
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 only do HTML/ASP when JS variable = true

How do i only run this JavaScript validation check if a JavaScript variable = true (infant = true;)

Code:
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" );
        //obj.focus();
        return;
    }

    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;
        document.form.submit();

    }
    else if( diff > 2 ) {
        alert( "This is NOT an INFANT \n they are older that 2" );
        infant = false;
        document.form.birthday.value = "";
        document.form.date.focus();
    }

}
<img src="g_toolbar_flights.gif" onClick="javascript: checkRetdt(document.form.retdt);" onMouseOver='style.cursor="hand"'>
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old July 19th, 2005, 05:06 AM
Authorized User
 
Join Date: Jul 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prophet Send a message via MSN to prophet
Default

Perhaps add this in the begining?
if(infant==false) {
   return false;
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML anchor and JS focus not working together sudhirgk Javascript 0 December 18th, 2007 06:29 PM
Variable in ASP HTML? thenextbillgates ASP.NET 1.0 and 1.1 Basics 0 April 7th, 2006 09:28 PM
use a JS-variable/function inside a tag cybermaarten Javascript 3 January 20th, 2005 05:42 AM
HELP: XSL -> HTML <select selected=true> jedbartlett XSLT 4 October 7th, 2004 11:16 PM
Yes/No in DB showing True/False in ASP query miller2000 Classic ASP Databases 2 June 17th, 2004 10:36 AM





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