PDA

View Full Version : Multipage form validation with javascript



jpearson311
April 20th, 2007, 04:19 PM
Hello all:

I'm building a multipage quote request form for a client of mine and I'm having some issues with the validation. I was wondering if anyone could possibly help me.

I have a simple form whoms action is set to delivery.php and it's onsubmit event handler is set as so:


onsubmit="javascript:validatePersonal()"The function validatePersonal looks like so:


function validatePersonal(){
if(document.form.name.value == ""){
window.alert("Please enter your name");
}
}The alert message is working fine if there is nothing in the form, but when I click ok, it still goes to the next page. How do I make it stay at the present page. Any help would appreciative. Thanks!

JPearson311

Roys
April 20th, 2007, 11:33 PM
Hi jpearson311 :),

Replace your code with the following


onsubmit="return validatePersonal();"



function validatePersonal(){
if(document.form.name.value == ""){
window.alert("Please enter your name");
return false;
}
return true;
}


:)

jpearson311
April 21st, 2007, 12:36 PM
Awesome. Thanks Roys! Much appreciated.

Jesse