...

View Full Version : undefined



crmpicco
07-04-2005, 10:39 AM
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?

glenngv
07-04-2005, 11:00 AM
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.

crmpicco
07-04-2005, 11:01 AM
.....
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
07-04-2005, 11:25 AM
How do i only do this code
document.form.TK.value=document.form.TK.value;
check(document.form);
when this variable = true
var submit_form=true;

Can i not reference a variable from another function in another function?

Heres my page:



<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
07-04-2005, 11:35 AM
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
07-04-2005, 11:39 AM
the fix:



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();
}

}

orhor
07-04-2005, 12:14 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum