Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate form without all the fields being cleared 1

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi,
I am using the following code to validate 2 list boxes on a form

Code:
<script language="JavaScript">
<!--
function validateform ()
{
  valid = true;

      if ( document.frmNewOrder.lstCust.value == "Select Customer" )
      {
              alert ( "Please Select a Valid Customer." );
			  document.forms['frmNewOrder'].elements['lstCust'].focus();
              valid = false;
      }

      else if ( document.frmNewOrder.lstStatus.value == "Select Status" )
      {
              alert ( "Please Select a Valid Status." );
			  document.forms['frmNewOrder'].elements['lstStatus'].focus();
              valid = false;
      }

        
      return valid;
}

//-->

</script>

and then have this on the submit button

Code:
<form id="form1" name="frmNewOrder" method="POST" action="<%=MM_editAction%>" onsubmit="validateform();">

This actually works Ok however after the alert has appeared and the Ok button is clicked all of the other fields on the form are cleared. is there anyway to achieve this validation without clearing all the fields.

any help is much appreciated.

Regards

Paul

 
Tricky one! Try this (to prevent the form being submitted if validation fails):
Code:
onsubmit="[!]return [/!]validateform();"
Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Hi BabyJeffy,

Thanks for the quick reply, tried your change and it worked a treat. A "Star" for you

Regards

Paul

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top