Field validation in JavaScript

I’ve done very little web development in Notes, and am having trouble figuring out where and how to validate a field when the user clicks Save & Close on the web.

I’ve tried Formula in the QuerySave, Formula in the Save & Close button, Javascript in the JS Header, and even Javascript in the Submit section. Nothing seems to stop the user from saving, let alone throw up an informational box.

What the heck am I doing wrong?

My JS code looks like this:

var form = document._F1;

// Added by Greg Gartland [11/30/2006] - field validation for ScratchPad

if (form.ScratchPad.value == “”){

alert(“You need to enter History at the bottom of this document”);

form.ScratchPad.focus();

return false;

}

Thanks!

Subject: Are you sure the form is called _F1?

You may want to view the page source and be sure the form is called _F1.

Where is your code? I suggest using the onSubmit event for the form. If you use the button to place your code than you will have to add code to call submit() if the field passed validation.

Howard

Subject: Field validation in JavaScript

@Prompt does not work on the web so you will need to code this in javascript.

I would put a validate function in the JSHeader

function validate(){

var f = document.forms[0];

// Added by Greg Gartland [11/30/2006] - field validation for ScratchPad

if (f.ScratchPad.value == “”){

  alert("You need to enter History at the bottom of this   document");

  f.ScratchPad.focus();

  return false;

}

//passed validation so submit form

f.submit();

}

and then in the save button

validate();