I Got The Form Validation Blues

Results 1 to 2 of 2

Thread: I Got The Form Validation Blues

  1. #1
    Join Date
    Dec 1969

    Default I Got The Form Validation Blues

    The Problem:<BR><BR>I&#039;m playing around with JS Form Validation for the first time and I&#039;m having a little trouble. The form fields are validating and popping up the little JS Warning Box, but as soon as I click ok, it submits the form anyway, even though a field has been left blank. <BR><BR>The Form:<BR><BR>&#060;form name="PlaceAd" method="POST" action="VerifyAd.asp?CatID=&#060;%=CatID%&#062;&Ca tType=notices" onsubmit="Validator(PlaceAd)"&#062;<BR><BR>&#060;/form&#062;<BR><BR>The Validation Script:<BR><BR>function Validator(PlaceAd)<BR>{<BR>if (PlaceAd.SubID.value == "")<BR>{<BR>alert("You Must Select A Sub Category!");<BR>PlaceAd.SubID.focus();<BR>return (false);<BR>}<BR>if (PlaceAd.header.value == "")<BR>{<BR>alert("You must enter a title.");<BR>PlaceAd.header.focus();<BR>return (false);<BR>}<BR>if (PlaceAd.Description.value == "")<BR>{<BR>alert("You have not filled out the ad form");<BR>PlaceAd.description.focus();<BR>return (false);<BR>}<BR>}<BR><BR>Can someone please tell me what I&#039;m missing, or doing wrong here? Thanks in advance for any help.

  2. #2
    Join Date
    Dec 1969

    Default onSubmit *must* return true/false

    You are missing the word "return" in the onSubmit:<BR><BR>&#060;form name="PlaceAd" ...onSubmit="return Validator(PlaceAd);"&#062;<BR><BR>And then BE SURE that ALL POSSIBLE ways of returning from your Validator function return either true or false!<BR><BR>In your code, as shown, you need to add a "return true;" at the end of the function (that is, if nothing fails, the entire function succeeds).<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts