Thursday, March 29, 2012

onSubmit want function to execute, not the form action

I have a login window that is being opened from a calling .asp page. When the window opens up it calls an .asp page. In this window you select the user name and then type in your password. After they type in their password and click on the submit button the onClick event fires and executes a function that passes the userid and password back to the calling form. If after entering in the password the user hits enter, the function is executed but the action on the form is also executed so I get the page that I am suppose to get with the function being executed, but when the action of the form is executed (because hitting the enter submits the form) then I also get an error page. How can I not get this error page? Someone told me that I need to have the function return false. They said that this would still allow the function to run, however, the form submittal would not run? Is that true? The function is in JavaScript, how do a return a false? Any help that can be provided would be very much appreciated.Strictly speaking from the client-side, to answer the question in regards to how to return false:

<form action="somefile.asp" method="post" onSubmit="return FunctionToCall();"
<script language="javascript">
function FunctionToCall()
{
//This is the stuff you want to happen
return false; // This prevents the submit from happening
}
</script>

Ciao
It worked perfectly. I was trying onSubmit="FunctionToCall();" instead of "return FunctionToCall();". Thank you!!

0 comments:

Post a Comment