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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter key won't send to document.location?

Status
Not open for further replies.

dimeod1

Programmer
Mar 31, 2011
1
US
For some reason the enterkey calls the functions but won't populate the next page unless the alert is there.

If I remove the alert the page will only send using the onclick event

Code:
<script language="javascript">
 
 var ZIPS ="07071/07072";
 var ZIPS2 ="07960/07961";

var zipArray = ZIPS.split("/");
var zip2Array = ZIPS2.split("/");

document.onkeypress = processKey;

function processKey(e)
{
  if (null == e)
    e = window.event ;
  if (e.keyCode == 13)
  {
    zipsearch();
  }
}
function zipsearch()
{
	  for (i=0;i<zipArray.length;i++)
	  {
		if (zipArray[i] == document.forms[0].zip.value)
		{
	document.location.href="2011/march/zone1/zone1.html";
			alert("");
			return true;
		}
if (zip2Array[i] == document.forms[0].zip.value.toUpperCase())
		{  
	         window.location="2011/march/zone2/zone2.html"
		 return true;
		}
   alert("That Zipcode is either invalid or not in our records!")
	  document.forms[0].zip.focus();
	  return false;
    }
 }
 </script>
</head>
<body onload="document.myform.zip.focus()"> 
 <form method="POST" name="myform">
 <input name="zip" id="zip" type="text" size="15" border="1"/>
 <input type="button" class="searchbutton" value="Search" onclick="zipsearch();" border="1" />
<input type="hidden" name="hiddendata"/>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top