Executing Wrong Function.

J

Jon Turlington

This works fine in IE but Firefox executes the wrong function(zipCode).

File: default.aspx

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>NDemand Reseller Site</title>
<script type="text/javascript" language="javascript"
src="main.js"></script>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body onload="checkLogin();">
<form id="form1" runat="server">
<div id="full_page">
<div id="header"><table width="100%"><tr><td width="50%"
align="left"><img src="art/ndemand_logo_bevels[vector-225px].gif"
/></td><td align="right">Reseller Site<br
/>866-933-7873</td></tr></table></div>
<div id="content"><div class="links"><a class="links"
href="add.aspx">Sign Up</a> | <a class="links"
href="payment.aspx">Payments</a> | <a class="links" onclick="logout();"
onmouseover="document.body.style.cursor='hand';"
onmouseout="document.body.style.cursor='auto';">Sign Out</a></div>
<div id="in" style="display:none;">Logged in.</div>
<div id="out" style="display:none;">You are not currently logged in.
Please login below:<br />
Username:<input id="tb_usr" type="text" /><br />
Password:<input id="tb_pwd" type="password" /><br />
<input id="submit" type="button" value="Submit"
onclick="staffAuth(document.getElementById('tb_usr').value,document.getElementById('tb_pwd').value);"
/>
</div>
</div>
</form>
</body>
</html>

File: main.js

// JScript File
// Create an instance of the XML HTTP Request object
if (window.XMLHttpRequest){

// If IE7, Mozilla, Safari, etc: Use native object
var oXMLHTTP = new XMLHttpRequest();

}
else if (window.ActiveXObject){

// ...otherwise, use the ActiveX control for IE5.x and IE6
var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
}


var cityID1;
var stateID1;
function zipCode(zip,cityID,stateID){
cityID1 = cityID;
stateID1 = stateID;

// Show hourglass to let them know something is going on.
document.body.style.cursor='wait';

// Prepare the XMLHTTP object for a HTTP POST to our validation ASP
page
var sURL = "zip.asp?zip=" + zip;
oXMLHTTP.open( "POST", sURL, false );

// Define an event handler for processing
oXMLHTTP.onreadystatechange = zipstatechange;

// Execute the request
try{
oXMLHTTP.send();
}
catch(e){
alert("Could not find zip code at this time.");
document.getElementById("zip").focus;
}
}

function zipstatechange() {

switch(oXMLHTTP.readyState){
case 4:
if(oXMLHTTP.responseText !== ""){
var response1 = oXMLHTTP.responseText;
var array1 = response1.split(",");
document.getElementById(cityID1).value=array1[0];
document.getElementById(stateID1).value=array1[1];
document.body.style.cursor='auto';
}
else {
alert("Could not find zip code");
}
}
}

function staffAuth(usr,pwd){
// Show hourglass to let them know something is going on.
document.body.style.cursor='wait';

// Prepare the XMLHTTP object for a HTTP POST to our validation ASP
page
var sURL = "auth.asp?usr=" + usr +"&pwd=" + pwd
oXMLHTTP.open( "POST", sURL, false );

// Define an event handler for processing
oXMLHTTP.onreadystatechange = authstatechange;

// Execute the request
try{
oXMLHTTP.send();
}
catch(e){
alert("Could not find zip code at this time.");
document.getElementById("zip").focus;
}
}

function authstatechange() {

switch(oXMLHTTP.readyState){
case 4:
if(oXMLHTTP.responseText !== ""){
var response1 = oXMLHTTP.responseText;
setCookie("staffnum",response1,30);
document.body.style.cursor='auto';
checkLogin();
}
else {
alert("The username and/or password you have entered is
invalid.");
}
}
}

function checkLogin(){
if(getCookie('staffnum') != null){
document.getElementById('in').style.display='block';
document.getElementById('out').style.display='none';
document.getElementById('tb_usr').value = "";
document.getElementById('tb_pwd').value = "";
}else{
document.getElementById('in').style.display='none';
document.getElementById('out').style.display='block';
}
}

function setCookie(c_name,value,expiredays)
{var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" :
";expires="+exdate);
}

function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1 ;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end));
}
}
return null
}

function logout(){
setCookie('staffnum',"",0);
checkLogin();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top