kinjohn
03-23-2005, 09:31 AM
I have the following Java codes:
function validate_form ( )
{
valid = true;
if ( enquire.txtname.value == "" )
{
alert ( "Please fill in the ' Name' box." );
valid = false;}
if ( enquire.txtemail.value == "" )
{
alert ( "Please fill in the 'Email' box." );
valid = false;}
if ( enquire.txtphone.value == "" )
{
alert ( "Please fill in the 'Phone' box." );
valid = false;}
if ( enquire.txtsubject.value == "" )
{
alert ( "Please fill in the 'Subject' box." );
valid = false;}
if ( enquire.txtmessage.value == "" )
{
alert ( "Please fill in the 'Message' box." );
valid = false;}
return valid;
}
The purpose of this code is to validate the textboxes when the submit button is click; to see whether they are empty or not. If it is empty, a message box will come up and say that field is empty.
I can run this code alright, but it doesn't quite do waht I really want it to do. If the user leave all 5 fields empty and lcik the submit button, five message box will show up. I don't want this to happen.
The way I want it to work is if the user doesn't input anything into the 5 field, the first field ( in my case, it is the name fireld) message box will come only. If the name field is filled in and the other four aren't, the "email" message box will come up. The rest follows this logic
Can some experts help me correcting my code plz
Thx
function validate_form ( )
{
valid = true;
if ( enquire.txtname.value == "" )
{
alert ( "Please fill in the ' Name' box." );
valid = false;}
if ( enquire.txtemail.value == "" )
{
alert ( "Please fill in the 'Email' box." );
valid = false;}
if ( enquire.txtphone.value == "" )
{
alert ( "Please fill in the 'Phone' box." );
valid = false;}
if ( enquire.txtsubject.value == "" )
{
alert ( "Please fill in the 'Subject' box." );
valid = false;}
if ( enquire.txtmessage.value == "" )
{
alert ( "Please fill in the 'Message' box." );
valid = false;}
return valid;
}
The purpose of this code is to validate the textboxes when the submit button is click; to see whether they are empty or not. If it is empty, a message box will come up and say that field is empty.
I can run this code alright, but it doesn't quite do waht I really want it to do. If the user leave all 5 fields empty and lcik the submit button, five message box will show up. I don't want this to happen.
The way I want it to work is if the user doesn't input anything into the 5 field, the first field ( in my case, it is the name fireld) message box will come only. If the name field is filled in and the other four aren't, the "email" message box will come up. The rest follows this logic
Can some experts help me correcting my code plz
Thx