Skip to content Skip to sidebar Skip to footer

Message Prompted Up Onsubmit Return Validate But Form Still Submits

I am having some issues which is quite similar referring to this onsubmit return false does not work, form still submits? I've followed the solution but if I changed it to onclick,

Solution 1:

I think this is because you're always returning true. In your JS, try this:

<script>functionvalidate()
{
  var validate = true;
  if(document.getElementById("nameId").value == "") {  
       alert("NAME IS REQUIRED");
       validate = false;
    }

    return validate;
}
</script>

Solution 2:

Well you always return true from Validate(). It should be more like the following:

<script>functionvalidate()
{
  var valid = true;
  if(document.getElementById("nameId").value == "")
  {  
    alert("NAME IS REQUIRED");
    valid = false;
  }

  return valid;
}

</script>

Solution 3:

solved your issue

<script>functionvalidate()
{
  var validate = false;
  if(document.getElementById("nameId").value == "")
{  
   alert("NAME IS REQUIRED");
   returnfalse;
   //validate   = false
}

returntrue ;
}

</script>

**update your script by this script **

Post a Comment for "Message Prompted Up Onsubmit Return Validate But Form Still Submits"