Form validation

Results 1 to 3 of 3

Thread: Form validation

  1. #1
    Join Date
    Dec 1969

    Default Form validation

    I am working on a form validation and have a question that need to validate based on the Yes or No answer on the previous question.<BR>If the answer is Yes, then the user must enter some info on the following question; but if the answer is no, then no need. <BR><BR>Here is the script that I have so far<BR><BR>//Question 1. Enter Yes or No<BR> if (theForm.lstHaveInfo.value == "")<BR> {<BR> alert("Please enter Yes or No on this question.");<BR> theForm.lstHaveInfo.focus();<BR> return (false);<BR> }<BR> <BR>//Question 2. If Yes must enter some info but if no, then no need to enter. <BR> if (theForm.txtAdditionalInfoNames.value == "") <BR> <BR> {<BR> alert("Please enter names of anyone else who may have additional info.");<BR> theForm.txtAdditionalInfoNames.focus();<BR> return (false);<BR> }<BR><BR>Thanks in advance<BR>

  2. #2
    Sreedharan Guest

    Default Here you are: Form validation

    Call the function fValidate to check for the value in "txtAdditionalInfoNames".<BR><BR>function fValidate()<BR>{ if (document.forms[0].lstHaveInfo.value == "Yes") {<BR> if (document.forms[0].txtAdditionalInfoNames.value == ""){<BR> alert("You must enter some value.");<BR> document.forms[0].txtAdditionalInfoNames.focus();<BR> return false; } }<BR> return true;<BR>}<BR> <BR><BR>In the case of the "lstHaveInfo", you already have the code. But make it into a function, which can be called in whichever event you want. Since you have not given your form layout, I cannot tell you what to do.<BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Here you are: Form validation

    Great! Thank you

Posting Permissions

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