Solved

Javascript form validation

Posted on 2006-06-29
2
387 Views
Last Modified: 2013-12-18
Hi all,

I have a small javascript function which I have placed in the JSHeader to validate one of the form field, then I am calling this from the onsubmit event.
This works perfectly fine and i know that I can add dozens of fields to validate on the same way and it will do this with no problems. However, I was looking for a way that i can group all these validation at the end of the function, the display all that fail validation in one box on submit as oppose to 10 alerts for 10 fields and take the focus back to the first field that fail the validation.

SCRIPT

function validRequired()
{
if (document.forms[0].productno.value == "")
{
alert('Please enter a value in the hose serial no field.');
document.forms[0].productno.focus();
return false;

}
}

onsubmit return validRequired()
 
This is a notes client that i am trying this valiation on.

Thanks
Varvoura
0
Comment
Question by:varvoura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
mshogren earned 500 total points
ID: 17010579
I use something like this.  Note that focusing on the field only focuses on the first error.

function validRequired()
{
  var strErr = '';

  if (document.forms[0].productno.value == "")
  {

    if (strErr == '')
    {
      document.forms[0].productno.focus();
    }
    strErr += 'Please enter a value in the hose serial no field.\n';
  }
  if (strErr == '')
  {
    return true;
  }
  else
  {
  alert(strErr);
  return false;
  }
}
0
 

Author Comment

by:varvoura
ID: 17022123
Thank you.

I modified your example to take into account all fields that i need to validate on and I got it to set the focus in the exact field that's missing. eg. If the first field that i am validating on passes validation & the second doesn't then the focus is set to the 2nd field.

Much appreciated help and the points are yours.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to add a username for multiple users in Lotus 6 127
Lotus notes email code 2 223
Lotus notes email code 13 103
LotusScript: Merge Data to Word File 22 121
For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question