Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: undefined

  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,094
    Thanks
    15
    Thanked 1 Time in 1 Post

    Angry undefined

    Code:
    function checkBirthday(obj) {
    	if( !/^(\d{1,2})(\d{1,2})(\d{4})$/.test(obj.value) ) {
    		alert( "Invalid date supplied - must be format DDMMYYYY" );
    		obj.focus();
    		return;
    	}
    		
    	var d = new Date();
    	var d2 = new Date(RegExp.$3, RegExp.$2, RegExp.$1);
    	var submit_form;
    		
    	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;
    		submit_form = true;
    	}
    	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();
    		document.form.date.select();
    		submit_form = false;
    		
    	}
    	
    
    }
    
    function confirmedok()
    {
    	if (!(submit_form==false));
    	{
    		document.form.TK.value=document.form.TK.value;
    		check(document.form);
    	}
    }
    I keep getting the error 'submit_form' is undefined

    Does var submit_form not define it?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    If you declare a variable with a var keyword inside a function, it is a local variable. Meaning, only the function can access it. If you want other functions to access it, make it global by declaring it outside the function.

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,094
    Thanks
    15
    Thanked 1 Time in 1 Post
    Code:
    .....
    		var submit_form=true;
    ....
    		var submit_form=false;
    
    .....
    
    function confirmedok()
    {
    	if (submit_form==true);
    	{
    		document.form.TK.value=document.form.TK.value;
    		check(document.form);
    	}
    }
    This successfully sets the variable to true/false. But i still get the error?

  • #4
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,094
    Thanks
    15
    Thanked 1 Time in 1 Post
    How do i only do this code
    Code:
    document.form.TK.value=document.form.TK.value;
    		check(document.form);
    when this variable = true
    Code:
    var submit_form=true;
    Can i not reference a variable from another function in another function?

    Heres my page:
    Code:
    <script language="javascript">
    function checkBirthday(obj) {
    	if( !/^(\d{1,2})(\d{1,2})(\d{4})$/.test(obj.value) ) {
    		alert( "Invalid date supplied - must be format DDMMYYYY" );
    		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" );
    		var infant=true;
    		var submit_form=true;
    		alert(submit_form);
    	}
    	else if( diff > 2 )
    	{
    		alert( "This is NOT an INFANT \n they are older that 2" );
    		var infant=false;
    		var submit_form=false;
    		alert(submit_form);
    		
    	}
    	
    
    }
    
    function confirmedok()
    {
    alert ("confirmedok");
    	if (submit_form==true);
    	{
    		document.form.TK.value=document.form.TK.value;
    		check(document.form);
    	}
    }
    </script>
    <img src="images/confirm.gif" onclick="javascript: checkBirthday(document.form.birthday); confirmedok();">

  • #5
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,094
    Thanks
    15
    Thanked 1 Time in 1 Post
    Code:
    function confirmedok()
    {
    alert ("confirmedok");
    alert (submit_form);
    	if (submit_form==true);
    	{
    	alert("286! Submit Form = true")
    		document.form.TK.value=document.form.TK.value;
    		check(document.form);
    	}
    
    }
    when submit_form = false it still runs through the 'true' if statement?

  • #6
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,094
    Thanks
    15
    Thanked 1 Time in 1 Post
    the fix:

    Code:
    function confirmedok()
    {
    alert ("confirmedok");
    alert (submit_form);
    	if (submit_form==true)
    	{
    	alert("286! Submit Form = true")
    		document.form.TK.value=document.form.TK.value;
    		check(document.form);
    	}
    	else 
    	{
    	alert("293 falsch")
    	document.form.date.focus();
    	}
    
    }

  • #7
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what do you mean with
    document.form.TK.value=document.form.TK.value; ?

    Maybe I can't see something, or don't know something, but I think this is completely meaningless statement.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •