View Single Post
  #1 (permalink)  
Old 03-15-05, 06:47 AM
Cepeleon Cepeleon is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Form Validation - Prevent submit if fields are blank

Hi,

I need to validate a form when the user hits submit.

Basically I want to say that if certain fields on the form have a value of " " then display a message box and prevent the form being submitted to the ASP file ELSE submit the form normally.

Now I came up with something but its not working because when I hit submit with the fields blank its being sent to the process.asp file with not message box appearing.

What is wrong with what I am doing?

In the header I put this,

Code:
function checkIt(f)
{   
if (f.elements['Field1name'].value=="" && f.elements['Field2name'].value=="")   
{      
alert('You have not specified the products you wish to order please go back to step 2');
     return false;   
}   
return true;
}
In the body I put this,

Code:
<form method="post" action="process.asp" name="sForm" onSubmit="return checkIt(this);">
...
Any ideas?
Reply With Quote