★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum3/HTML/000434.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  JavaScript
  Direct back to form field

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   Direct back to form field
nsmith
Junior Member
posted July 12, 2000 01:28 PM     Click Here to See the Profile for nsmith   Click Here to Email nsmith     Edit/Delete Message Reply w/Quote
I have setup a form with required fields using Javascript. I would like to know how to send the user back to the field that did not fill, once they click on the error message.

billyo
Member
posted July 13, 2000 01:48 PM     Click Here to See the Profile for billyo   Click Here to Email billyo     Edit/Delete Message Reply w/Quote
If the extent of your validation is simply whether or not a field is blank, you could use this.
code:
<script language="javascript"><!--
function Validate()
{
for (i=0;i<document.forms[0].elements.length;i++)
{
if (document.forms[0].elements[i].value=="")
{
alert("yo fool, you left " + document.forms[0].elements[i].name + " blank");
document.forms[0].elements[i].focus();
return false;
break
}
}
}
//--></script>


and your form would look like this...
code:
<body>
<form><input type=text name=text1><input type=text name=text2><input type=text name=text3><input type=text name=text4></form>
<a href=javascript:Validate()>Validate</a>
</body>


I think that'll work reasonably well in both major browsers.

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.