Q

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>


This was first published in May 2002

Dig deeper on Domino Resources - Part 3

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • 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 ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close