Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Question form validation problem

    Hello,
    I'm trying to use the fallowing script for form valildation, it does give me the alert message when feilds are not completed, but when I click ok, it submits the page anyway,,
    any ideas???

    thanks in advance for your time!

    PHP Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    function 
    checkform form )
    {

      if (
    form.fname.value == "" &&
            
    form.lname.value == "" &&
            
    form.phone.value == "" &&
            
    form.serv.value == "" &&
            
    form.month.value == "-" &&
            
    form.day.value == "-" &&
            
    form.time.value == "-")
            {
    alert"Please complete all feilds!" );
    form.email.focus();
    return 
    false ;
            }

      
    //return true ;
    }
    //-->
    </script>
    <form action='sendmail.php' method='post' onsubmit="return checkform(this);"> 

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    907
    Thanks
    0
    Thanked 119 Times in 118 Posts
    you have set it to only return false when no fields are filled by using the &&;
    an beside that you have made a few typo's
    the correct script is:
    Code:
    function checkform (form)
    {
    
      if (form.fname.value == "" ||
            form.lname.value == "" ||
            form.phone.value == "" ||
            form.serv.value == "" ||
            form.month.value == "-" ||
            form.day.value == "-" ||
            form.time.value == "-")
            {
    alert("Please complete all fields!");
    form.email.focus();
    return false;
            }else{
    return true;}
    }
    }
    if month day and time is chosen from a dropdownmenu then you must use:
    e.g. form.day[form.day.selectedIndex].value
    Last edited by Lerura; 10-24-2005 at 02:30 AM.


  •  

    Posting Permissions

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