Click to See Complete Forum and Search --> : javascript on secure pages


markjbrill
06-18-2003, 08:16 PM
Here's my problem. My webstore outputs a dynamically generated order form in which I validate the e-mail address. The order form is served via a secure server and the javascript to validate resides in the head portion of the page. There are three functions involved with the validation. First-I detect whether the submit button or the enter key was used to submit the form ( I want submit button use only). Second-the form name and field name to validate are passed to a function to determine the field name subscript in the form array (since the order page is dynamically generated the e-mail field subscript varies). Third-the function which does the actual validation is called with the correct form name and e-mail field subscript. The validation works fine but the first time I try to submit the form after starting IE I get a "you about to leave a secure page ...." with options to continue, cancel or get more info message. If I cancel and immediatly resubmit the form I don't get the message. And it doesn't appear again until I've closed IE and restart. This is probably clear as mud but any help will be appreciated.

Why does IE think it's leaving a secure page?


Below is the javascript code and the submit code.

<script language="JavaScript">
var nav4 = (window.Event) ? true : false;
var ie4 = (window.Event) ? true : false;

if (nav4)
{document.captureEvents(Event.KEYPRESS);}

{ document.onkeypress = processKeyStroke;}

function processKeyStroke (e)
{
if (nav4)
{
if (e.which == 13)
{
alert ("Please Click A Button.\nThanks.");
return false;
}
else
{return true;}
}
else
{
if (event.keyCode == 13)
{
alert ("Please Click A Button.\nThanks.");
event.returnValue = false;
}
else
{event.returnValue = true;}
}
};

var email, subscript;
function verify(formName,fieldName)
{
for (var i=0; i<(document.forms.length); i++)
{
if(document.forms[i].name == formName)
{subscript = i;}
}
for (var i=0; i<document.forms[subscript].length; i++)
{
if (document.forms[subscript].elements[i].name == fieldName)
{email = document.forms[subscript].elements[i].value;}
}
return validEmail(email);
}

var chkDot = true;
var usEmail = true;
function validEmail(eAddr)
{
var lenSuffix = (usEmail) ? 4 : 3;
var goodAddr = false;
var space = ndxAt = ndxDot = ndxDot2 = 0;

space = eAddr.indexOf(" ");
ndxAt = eAddr.indexOf("@");
ndxDot = eAddr.indexOf(".");
ndxDot2 = eAddr.lastIndexOf(".");

if (space > 0)
alert("Your email address contains blank spaces.\nPlease correct and click 'Submit'");
else if ( (ndxDot < 0) || (ndxAt < 0) )
alert("Your email address lacks '.' or '@'.\n\nThe format is 'you@dom.xxx'\nPlease correct and click 'Submit'");
else if (chkDot && (ndxDot < ndxAt) )
chkDot =!( confirm("You entered a 'dot' before the '@'\n Are you sure that is right?\n'Yes' Please click 'Submit' again."));
else if ( (ndxDot2 - 3) <= ndxAt )
alert("You may be missing your domain name\nor have forgotten the domain suffix.\n\nThe domain name must be at least 3 characters.\nThe format is 'you@dom.xxx'\nPlease correct and click 'Submit'");
else if ( eAddr.length < (ndxDot2 + lenSuffix) )
usEmail =!( confirm("You have fewer than 3 characters as a domain suffix.\nAre you sure that is right?\n'Yes' Please click 'Submit' again."));
else if (usEmail && (eAddr.length > (ndxDot2 + 4)))
alert("You have more than 3 characters as a domain suffix.\n\nThe format is 'you@dom.xxx'\nPlease correct and click 'Submit'");
else if (!usEmail && (eAddr.length > (ndxDot2 + 3)))
alert("You have more than 2 characters as a domain suffix.\n\nThe format is 'you@dom.xx'\nPlease correct and click 'Submit'");
else
goodAddr = true;

return (goodAddr);
}
</script>

<FORM name="orderFrm" METHOD = "post" ACTION = "https://s19.sslnet.com/vitastic/Web_store/web_store.cgi" onSubmit="return verify('orderFrm','14-e-mail');">

markjbrill
06-18-2003, 09:02 PM
Sorry, I was mistaken. I can't seem to consistantly generate the leaving of the secure page warning.