Skip to main content

How to Do Simple Javascript Field Validation on the Web using Domino

Why Javascript?
If you're like me and not really a domino developer, but a bit of everything, then you probably don't have a lot of time to spend on learning all the tips and tricks of domino. Often, creating a database is simply a matter of "knocking together" forms and views that will do the job and putting only minimal validation in place.

The problem is that normal built-in notes validation is awful on the web. You need to submit a form and get a validation "knockback" then click the back button in your browser and re-fill in the form. (Unless you have a modern version of firefox which seems to remember form data prior to submission).

In any case, what you really want is something that neatly informs you that you've missed something. The way to do this on the web is to use Javascript.


Disclaimer The technique I'm going to use here is an old one. If you're a seasoned Javascript developer, you'll certainly have much better methods. I'm not trying for an elegant solution, I'm just trying to do something simple.

A word of caution: Javascript is case sensitive, so be sure to check your case very very carefully. It can save hours of debugging afterwards.

About our Example Form
In order to explain this example, we need to have a form that we can display on the web. For the purpose of display, I'm going to assume that we have this simple form.

It has three fields on it.

  • FirstName
  • LastName
  • $Return

It also has one button.

The validation rule that we're going to apply is simply that no field can be blank. Both fields are to be mandatory.

oh, and the Designer client I'm using is 7.0.2

So, here goes...


The JS Header
Open your form in Designer and look for the JS Header part of the form (on the Objects Tab).
Put the following code there under WEB and JAVASCRIPT



The code is as follows;
(my apologies for using images - I was just worried about it being interpreted by blogger).



You should notice that each field has three bits that should be modified;

  1. The alert message telling you what is wrong
  2. The if (f.FirstName.value=="") bit which specifies the field to be checked
  3. f.FirstName.focus(); bit which refocuses the cursor on the offending field.


The OnClick Event
Now, In the OnClick event of your button, under Web and Javascript, put the following;



Apparently, and I don't know the reasons for this, you also have to have the following on the same button under Client and Formula



The $$Return Field
These changes should be enough to get your form working but I've discovered that a lot of people don't know about the $$Return field, so it's probably worth mentioning it too.

The $$Return Field should be a hidden (from Notes and Web) computed field
The formula for this field should be something like the following - though you'd probably replace the google.com reference with the address of a "thank you for submitting" page in your database.


So now, you should have a form you can use.
If your database is called mydatabase.nsf and if it's in the \test folder of your server and if your form is called myform, then you should be able to get to the database by doing the following;

http://mydomain.com/test/mydatabase.nsf/myform?OpenForm&Login

Depending on security, you might not need &Login
also; if you don't have a domain (for the mydomain.com bit), you could simply use the IP Address of your server if you're inside the firewall.

Right, so now that you can test for blanks, you can start modifying the code to test for more exciting things.

Comments

Anonymous said…
Hej Gavin,

I have described a different approach using LS and a simple @filesave action underneath a button:

http://quintessens.wordpress.com/2007/08/30/user-profile-documents-mandatory-fields/

Hows Domino development in Downunder? (just curious how the job market is there, quiet hard to get in from abroad isn't?)

// cheerio! Patrick
Gavin Bollard said…
Hi Patrick,

Your link was quite good and is certainly more functional that my example here.

Notes/Domino has been picking up in Australia of late and the recession doesn't seem to be affecting IT jobs here yet.

We are however, seeing a housing slump combined with rising interest rates (and fuel prices), so I think things will get dicey soon.

I'm not sure if it would be difficult to get into such a position from abroad having never done that myself. You'd probably be best off talking to some Australian agencies.

Popular posts from this blog

How to Create a Bootable DVD Using Nero Burning ROM 9

I often need to create bootable CDs and DVDs but it's weird because I frequently end up buring myself a new coaster instead. It's not that the process is difficult, just that nero has a few too many options and I forget which ones to choose and end up picking the wrong one. I figured that the best way to avoid this mistake in future would be to write the steps down. Procedure Insert CD or DVD into your DVD Burner. Start Nero Burning ROM 9 Choose DVD-ROM (Boot) or CD-ROM (Boot) depending on what you're creating You'll be prompted for a disk image source. Choose a Nero Source - you'll usually find them somewhere like this... C:\Program Files\Nero\Nero9\Nero Burning Rom\DOSBootImage.ima Leave the Boot Locale as English - unless you really need a different keyboard layout Tick the box marked [X] Enable Expert Settings Choose Hard Drive Emulation and leave any other settings as they are. Click the button marked New Add any files you want but don't try to add operati

How to Change Your Notification Options for New Lotus Notes Mail in version 8.x

Don't worry, I'm not patronizing you (my readers), I just decided to re-document this for one of our internal users and thought you might want to be able to use it in your own user documentation. WHAT IS THIS DOCUMENT ABOUT? Some people who don't get a lot of mail, like to be notified when such an event occurs. Notification can be; via a sound via a pop-up box via the system tray (where the computer clock is) The pop up box looks like this; Other people, who like myself, get too much mail would rather not be notified. The aim of this document is to tell you how (and where) to turn these options on and off. CHANGING YOUR SETTINGS To change your settings from the Notes 8.x client; On the Menu, click File , then Preferences... On the left hand side , click on the little plus sign to the left of Mail to expand the options. Click on the option marked Sending and Receiving . In the middle section, under receiving, you can control your notifications. If you untick the box mark

How to Create an Auto-Response Mail Message in Lotus Notes 8.5.3+

Why would you do this? Suppose that you have an externally accessible generic email address for your company; support@mycompany.com or info@mycompany.com. You might expose this to the web and allow people to send messages to you. Setting up an auto-response email will tell the senders that their message reached its destination and that it will be dealt with accordingly.  It's also good practice to include links to FAQs or other useful information. Why 8.5.3 The techniques we'll be using here work in older versions of Notes but some of the options seem to have moved around in 8.5.3.  I figured it was a good time to show you where they've moved to. The Procedure Start Domino Designer and open the Mail file to be modified.  A really quick way to do this is to right-click on the application tab and choose "Open in Designer". In the Left hand panel of designer, expand Code and then double-click Agents.  A new window should appear. Click the action