Validating form input with Java Script is easy to do and can save a lot of unnecessary calls to the server as all processing is handled by the web browser.
It can prevent people from leaving fields blank, from entering too little or too much or from using invalid characters.
We assume that you have some experience developing applications using Domino Designer and Lotus Script.
Field Get Text("rtfield") trimmed$ = Trim(text) if ( trimmed$ = "") Then Msgbox "Please enter some text." Continue = False source. Refresh(True) Else Continue = True End If End Sub Our third method validates a rich text field in which an input consisting solely of an attachment, embedded object, or link is allowed, even if it includes no accompanying text.
Once again, we use the Querysave event of the form containing the field: Sub Querysave(Source As Notesuidocument, Continue As Variant) Dim rtitem As Notes Rich Text Item Set doc = Source. Get First Item( "rtfield" ) Dim text As String text$ = Source.
The value of a text input box (or a textarea or password input) is available using the syntax that tells you which option has been selected.
The illustration below shows this relationship: Note that the 'I' in selected Index needs to be capitalised - Java Script functions and variables are always case-sensitive. Read more about the humble checkbox in our HTML5 Checkbox Validation article.
If you're working with arrays of checkboxes to submit data to a server-side script then you might already have some grey hairs from trying to figure out how to validate the input using Java Script.
The problem is that, to have the data submitted in a 'nice' format to the server, the function returns an array containing all the selected checkbox values. In more complicated forms you will want to set conditions on the form that combine multiple elements.
This tip describes three quick methods for validating a rich text field in Lotus Notes.
The first method validates a text field in which any text (including a single space character) is an acceptable input.
Field Get Text( "rtfield" ) = "" ) Then Messagebox( "Please enter some text." ) Call Source.