Lotus Notes FAQ Visit Our Sponsor!

How do you add a Javascript button which validates the form and then submits it?

Your checkForm function should have the code to validate as well as submit. Your button should be of the type "button" and not submit. If the validation fails make an early exit from the function.

Add the following code in the $$HTMLHead field:

"<SCRIPT LANGUAGE=\"JavaScript\"> 
function checkForm() {
  if (document.forms[0].Name.value == \"\") {
      alert(\"You must enter your name\");
      return false;
  }
  document.forms[0].submit();
  return true;
}
</script>"

Add this code for a submit button as passthrough HTML or with the HTML style:

  <INPUT TYPE="Button" VALUE="Submit" onClick="checkForm(0)">

Now that you've added a special button, you'll have to remove the default one that Domino generates via the FAQ on how to remove the submit button.


Applies to Notes Versions: 4 4.5 4.6 5 6 6.5 7
Last Modified: May 24, 2005