Link to home
Start Free TrialLog in
Avatar of darrennelson
darrennelson

asked on

Onsubmit cancel

I'm trying to validate form data.  My functions seem to be working, but when returning false, the form action still takes place.

<Script Language = "JavaScript" type = "text/javascript" > 
      function validate_required(field,alerttxt)
      {
            with (field)
            {
                  if (value==null||value=="")
                  {
                        alert(alerttxt);
                        return false;
                  }
                  else
                  {
                        return true;
                  }
            }
      }
            
      function formvalid(thisform)
      {
            with (thisform)
            {
                  if (validate_required(disk_number, "Disk Number must be entered")==false)
                  {
                        id.focus();
                        return false;
                  }
                  else
                  return true;
            }
      }
</script>

<form name="form_input" method="post" onsubmit="return formvalid(this)" action="input.asp">

if formvalid() returns false, shouldn't the action be aborted?  If I leave 'disk_number' blank, I get an alert with the approriate message, but the 'input.asp' still executes.

any ideas?
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of darrennelson
darrennelson

ASKER

thanks guys, I had to implement pieces of both solutions.

function formvalid(thisform)
     {
          if (thisform.value==null||thisform.value=="")
          {
               alert("Disk Number must be entered");
               form_input.disk_number.focus();
               return false;
          }
          else
          {
               return true;
          }
     }

works great now, thanks again
Your welcome!  I'm glad that I could be one of those that helped.  Thank you for the grade, the points and the fun question.

bol