Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Trigger Best Practice

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I have a form and need to validate three of the input fields (firstname, lastnane, ssn). However, they are not used on the action page when the form is submitted. They are used to populate a select object on the same form so the user can add to the select contents. This behavior is triggered by the onClick event of a input with “button” for its type.

What is the correct event to use to trigger my validation function? I was thinking onBlur but I don’t have much experience in these matters.

Since the three inputs are in the same form, the entire form is submitted if the user hits the enter key. Can forms be nested? If so can I reference either form in a function?

Sorry if this request is rather disorganized, it simply reflects my current mental state. LOL

Any help appreciated.
Lyndon

 
If you want to validate onblur, will you want the validation to take place only if all 3 inputs are filled in, or as each one is filled in?

You can also use something like:

Code:
function validateall()
{
var thisform = document.forms['thisform'];
if (thisform.elements['firstname'].value.length==0)
  {
  return false;
  }

if (thisform.elements['lastname'].value.length==0)
  {
  return false;
  }

if (thisform.elements['ssn'].value.length==0)
  {
  return false;
  }

return true;
}
<form name="thisform" onsubmit="return validateall();">
<input type="text" name="firstname">
<input type="text" name="lastname">
<input type="text" name="ssn">

</form>

to validate when the form is submitted or prevent submission from taking place if all 3 inputs aren't filled in.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top