Problem solve Get help with specific problems with your technologies, process and projects.

Code for validation on a field

I would like to ask you if you have JavaScript code which does the validation on a field. If nothing is put in to the field from the user, a warning pops up and reminds the user that the field has to be filled in or something. I would appreciate it if you can help me on this.
The following code contains HTML and JavaScript that implements one simple way of doing this. You should be able to save the following code as an HTML file in your file system to test it. You could put the JavaScript functions in the JSHeader event of your form and add the call to ValidateForm in the form's onSubmit event.

 &lthtml> &lthead> &lttitle&gtSearchDomino Test</title> &ltSCRIPT language="JavaScript"> function validateForm(form){ // Last mods 020518 - dhatter@libertastechnologies.com - www.libertastechnologies.com with(form){ if(! isFieldEmpty(email)){ return(false); } return(true); } } function isFieldEmpty(objField){ // Last mods 020518 - dhatter@libertastechnologies.com - www.libertastechnologies.com if(objField.value==''){ alert('Please enter a value for ' + objField.name + '.'); objField.focus(); return(false); }else{ return(true); } } </SCRIPT> </head> &ltbody> &ltFORM action="" method="POST" onSubmit="return(validateForm(document.forms[0]))"> e-Mail Address: &ltINPUT name="email" value="" type="text">&ltBR> &ltINPUT type="submit" value="Submit"> </FORM> </body> </html>

Dig Deeper on Domino Resources - Part 3

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...