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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Howto do onBlur field validation in form with more fields

Status
Not open for further replies.

431964

Programmer
Jan 20, 2000
3
0
0
MY
Hi,<br>
<br>
I want my form validation to be on a field by field basis.<br>
Therefore I use the onBlur() event. <br>
<br>
Problem is that depending on the user action. Mouse is move is oke but tab produces a browser lockup between the field that is left and the next one its about to enter.<br>
<br>
<br>
I do like this:<br>
<br>
in: verify.js<br>
<br>
----knip-------<br>
//&lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;<br>
<br>
function senderCheck() {<br>
<br>
if (document.forms[0].sender.value.length == 0 ) {<br>
ErrorMsg(&quot;Sender name is mandatory!&quot;);<br>
document.forms[0].sender.select(); <br>
}<br>
}<br>
//=end=====================================================<br>
<br>
function recipCheck() {<br>
<br>
if ( document.forms[0].recipient.value.length == 0 ) {<br>
ErrorMsg(&quot;No Recipient name is given!&quot;);<br>
document.forms[0].recipient.select(); <br>
}<br>
}<br>
<br>
remark: ErrorMsg is just a alert() function.<br>
These functions are nearly identical but must stay apart for other reasons.<br>
----knip-------<br>
<br>
<br>
in sendsome.htm<br>
<br>
----knip-------<br>
&lt;head&gt;<br>
&lt;script type=&quot;text/javascript&quot; language=&quot;JavaScript&quot; src=&quot;verify.js&quot;&gt;&lt;/script&gt; <br>
&lt;/head&gt;<br>
----knip-------<br>
&lt;form name=&quot;theForm&quot; method=&quot;post&quot; action=&quot;../../cgi-bin/some.cgi&quot; target=&quot;content&quot;&gt;<br>
sender:<br>
&lt;input type=&quot;text&quot; size=&quot;35&quot; name=&quot;sender&quot; onBlur=&quot;senderCheck()&quot;&gt; *<br>
recipient:<br>
&lt;input type=&quot;text&quot; size=&quot;35&quot; maxlength=&quot;25&quot; name=&quot;recipient&quot; onBlur=&quot;recipCheck()&quot;&gt; *<br>
&lt;input type=&quot;submit&quot; value=&quot;Send&quot;&gt;<br>
&lt;input type=&quot;reset&quot; value=&quot;Cancel&quot;&gt;<br>
&lt;/form&gt;<br>
<br>
----knip-------<br>
<br>
<br>
and besides, is there anybody out here who has some advise <br>
or pointers on to some handy tools for writing and DEBUGGING JavaScript code ? <br>
Netscapes debugger didnt work (js error prevented downloading, anyway didnt found the app)<br>
<br>
Ohja it must work offline aswell<br>
<br>
<br>
Thank you all very much<br>
<br>
<A HREF="mailto:sluiter@cmpmail.com">sluiter@cmpmail.com</A><br>
<br>
<br>

 
Hmmm...<br>
No errors in the code are jumping out at me in my currnet (slightly exhausted) state of mind; but in answer to your final question, check out <A HREF=" TARGET="_new"> it's an <i><b>excellent</i></b> resource for internet programming (including JavaScript and dHTML) <p>-Robherc<br><a href=mailto:robherc@netzero.net>robherc@netzero.net</a><br><a href= > </a><br>*nix installation & program collector/reseller. Contact me if you think you've got one that I don't :)
 
try
..... onChange=&quot;whateverCheck()&quot;>....
If the user moves from the field at all it will run the function. X-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top