Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-04-2005, 09:39 AM   PM User | #1
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
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?
crmpicco is offline   Reply With Quote
Old 07-04-2005, 10:00 AM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 07-04-2005, 10:01 AM   PM User | #3
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
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?
crmpicco is offline   Reply With Quote
Old 07-04-2005, 10:25 AM   PM User | #4
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
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();">
crmpicco is offline   Reply With Quote
Old 07-04-2005, 10:35 AM   PM User | #5
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
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?
crmpicco is offline   Reply With Quote
Old 07-04-2005, 10:39 AM   PM User | #6
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
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();
	}

}
crmpicco is offline   Reply With Quote
Old 07-04-2005, 11:14 AM   PM User | #7
orhor
New to the CF scene

 
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
orhor is an unknown quantity at this point
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.
orhor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:27 PM.


Advertisement
Log in to turn off these ads.