Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: open

Submit Onclick event does not work on IE

   
3:43 am on Oct 12, 2008 (gmt 0)

5+ Year Member



I have a form:

<form name="bookp" id="bookp" method="POST" action="page.php" onSubmit="return ValidateE()">

And the submit button


<input name="submit" id="submit" value="Submit" onClick="validateFor = 0;">

and the script,


function ValidateE() {
if (validateFor == 0)
{
if (IsEmpty(document.getElementById("bookp").corpcontact)) {
alert("Please Enter Full Name");
document.getElementById("bookp").corpcontact.focus();
return false;
}
return true;
}
}

All this works perfectly in Firefox/safari but not on IE.. any help ?

4:51 am on Oct 12, 2008 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



welcome to WebmasterWorld, cybertai!

you've got two things happening triggered by the same action, which are dependent on happening in a particular order. Not ideal.

put an alert() into the onclick and consubmit events. see which IE executes first - the "click", or the "submit". maybe the onsubmit is happening before the onclick? test it in FF, OP, SF, IE, GC, etc. If the submit is happening before the click, "validateFor" will be undefined when validateE() is triggered.

what is validateFor for?
there's got to be another way to accomplish the same thing

you may have discovered one of the plethora of subtle nuances wherein browsers behave inconsistently. it is helpful to us all if you could diagnose it definitively and publish your findings

11:57 am on Oct 12, 2008 (gmt 0)

5+ Year Member



If you have an onSubmit method in your FORM tag doesn't it need to perform the form["bookp"].submit() ?

Is IE case sensitive about onSubmit ? (just looking at some of my code I am referencing it as "onsubmit")

We just put the JavaScript validation routine in the OnClick for the SUBMIT button - something like:

<input name="submit" id="submit" value="Submit" onClick="return MySubmit();">


function MySubmit()
{
var MyForm = form["bookp"];
if (typeof MyForm === "undefined")
{
alert("MyForm Object is undefined");
} else
{
// Perform validation
if (MyForm.onsubmit())
{
MyForm.submit();
}
return false;
}
}
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month