Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'event' is null or not an object

Status
Not open for further replies.

buzzt

Programmer
Oct 17, 2002
171
CA
Why do I keep getting this error? The script works, but there is still this error.

Here is the script:
Code:
<script language="JavaScript" type="text/JavaScript">
<!--
function formval()
{
if (document.form.formfield.value=='')
{
alert("Please enter your search.")
event.returnValue=false;
}
}

var formWin = null;
function openFormWin() 
{
if (document.form.formfield.value=='')
{
alert("Please enter your search.")
event.returnValue=false;
}
formWin = open('search.php','formWin','width=555,height=450,scrollbars=yes,left=150,top=100');
if (formWin && !formWin.closed) formWin.focus();
return true;
}
function noenter() {
return !(window.event && window.event.keyCode == 13); }

function schedule()
{
 open('schedule.php','Schedule','width=555,height=450,scrollbars=yes,left=150,top=100');
}
//-->
</script>

Here is the href
Code:
href="javascript:formval();openFormWin();document.form.submit();void(0)" alt="Search!"
 
Now it's 'window.event' is null or not an object.

??
 
Actually yes... if you used something like

<A href="javascript:formval();...void(0);">

... then event object won't be available. Use this instead ("javascript" prefix may not be necessary but anyway):

<A href="javascript:void(0);" onclick="javascript:formval();...">



 
Well, that stops the error, but the window still opens. I need for the script to just stop everything when that alert comes up.
 
Huh?

Am I missing something?

Does this work?

[tt]<a href="#" onclick="...; ...; return false;">[/tt]

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
That's another problem. In this code:

javascript:formval();openFormWin();document.form.submit();

... event.returnValue won't stop execution after formval(). Do it old-fashioned way:

Code:
<A href="javascript:void(0);" onclick="javascript:formval();">...</a>

function formval()
{	var bOK = true;
	if (document.form.formfield.value=='')
	{	alert("Please enter your search.")
		bOK = false;
	}

	// blah blah

	if (bOK)
	{	openFormWin()
	}
}
Also note that window opens asynchronously - code will automatically continue after openFormWin(). I have no idea how code flow is supposed to look like... maybe you need modal dialog instead of normal window.
 
I fixed it. Here's what I ended up with (in case anybody ends up in a similar situation):
Code:
<script language="JavaScript" type="text/JavaScript">
<!--
var formWin = null;
function openFormWin() 
{
	if (document.form.formfield.value=='')
		{
			alert("Enter search criteria")
			window.event.returnValue=false;
		}
	
	else
	{
		formWin = open('schedule.php','formWin','width=555,height=450,scrollbars=yes,left=150,top=100');
		if (formWin && !formWin.closed) formWin.focus();
		return true;
	}
}

function noenter()
{
	return !(window.event && window.event.keyCode == 13); 
}

function search()
{
	document.form.submit();
}
//-->
</script>

And the href... (made a big difference)
Code:
href="javascript:search();" onClick="openFormWin();">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top