intercepting the submit event

S

scott cooper

I want to intercept the submit event for field validation to cancel this
action if validation failes. I tried to script using the submit method and
also use the FireEvent("OnSubmit") method but neither option submited the
form. Is there another way to do this?
 
M

Mark Schupp

That's a client-side question that would be better asked on a client-side
group. However:

<form name="myform" action="myaction.asp" onsubmit="return
validate_form(this);"

Then add a script function to check each field

function validate_form(theForm)
{
//if a validation fails then return "false"

//first and last names are required
if( trim( theForm.fname.value ).length &lt; 1 )
{
alert( "first name is required" );
theForm.fname.focus();
return( false );
}
if( trim( theForm.lname.value ).length &lt; 1 )
{
alert( "last name is required" );
theForm.lname.focus();
return( false );
}

return( true );

}
 

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

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top