473,549 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arrgh.. Insane looping for focus()

Here is some javascript checking I have for form validation. The
problem is is that it loops..... How can I make it stop ? IF I click
on the last name text box, it scolds me, saying the first_name needs
to be filled out. I click ok, and it says the last_name needs to be
filled out...i click ok and it says the first_name needs to be
filled.. wash rinse repeat !!!!

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf ("?"))>0&&paren t.frames.length ) {
d=parent.frames[n.substring(p+1 )].document; n=n.substring(0 ,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.fo rms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.l ayers&&i<d.laye rs.length;i++)
x=MM_findObj(n, d.layers[i].document);
if(!x && document.getEle mentById) x=document.getE lementById(n);
return x;
}

function MM_validateForm () { //v4.0
var i,p,q,nm,test,n um,min,max,erro rs='',args=MM_v alidateForm.arg uments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj( args[i]);
if (val) { nm=val.name; if ((val=val.value )!="") {
if (test.indexOf(' isEmail')!=-1) { p=val.indexOf(' @');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain
an e-mail address.\n';
} else if (test!='R') {
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf(' inRange') != -1) { p=test.indexOf( ':');
min=test.substr ing(8,p); max=test.substr ing(p+1);
if (val<min || max<val) errors+='- '+nm+' must contain a
number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+er rors);
document.MM_ret urnValue = (errors == '');
document.forms['form0'][nm].focus();
}

<form name="form0" method="post" action="palm-beta.asp?action =add">
<table class="table_co ntent" border="0" cellpadding="3"
cellspacing="0" >
<tr class="box_left "><td><b>Fi rst Name</b></td></tr>
<tr class="box_righ t"><td><inpu t type="textbox" name="First_Nam e"
maxlength="20" size="21"
onBlur="MM_vali dateForm('First _Name','','R'); return
document.MM_ret urnValue"></td></tr>
<tr class="box_left "><td><b>La st Name</b></td></tr>
<tr class="box_righ t"><td><inpu t type="text" Name="Last_Name "
maxlength="20" size="21"
onBlur="MM_vali dateForm('Last_ Name','','R');r eturn
document.MM_ret urnValue"></td></tr>
<tr class="box_left "><td><b>Em ail Address</b></td></tr>
<tr class="box_righ t"><td><inpu t type="text" Name="Email_Add ress"
maxlength="50" size="51"
onBlur="MM_vali dateForm('Email _Address','','R isEmail');retur n
document.MM_ret urnValue"></td></tr>
<tr class="box_info "><td>&nbsp ;</td></tr>
<tr class="box_info "><td><inpu t type="submit" name="addemail"
value="Submit" class="button"> </td></tr>
</table>
</form>
Jul 20 '05 #1
2 1871
On 03.7.29 5:02 PM, Craig wrote:
Here is some javascript checking I have for form validation. The
problem is is that it loops..... How can I make it stop ? IF I click
on the last name text box, it scolds me, saying the first_name needs
to be filled out. I click ok, and it says the last_name needs to be
filled out...i click ok and it says the first_name needs to be
filled.. wash rinse repeat !!!!


This is the sort of annoying behaviour you get when you use onBlur events to
validate form input.

Be nice and use an onSubmit checker instead.

Philip Ronan
ph***********@v irgin.net
(Please remove the "z"s if replying by email)
Jul 20 '05 #2
Lee
fu************* **@hotmail.com said:

Here is some javascript checking I have for form validation. The
problem is is that it loops..... How can I make it stop ? IF I click
on the last name text box, it scolds me, saying the first_name needs
to be filled out. I click ok, and it says the last_name needs to be
filled out...i click ok and it says the first_name needs to be
filled.. wash rinse repeat !!!!


Don't validate onBlur. Use onChange, if you must validate immediately.
You'll have to validate again onSubmit (and, of course, again on the server).

100 You click the "last name" box, giving it focus.
200 Since focus left the "first name" box, the popup message appears.
300 Then your code sets focus back to the "first name" box.
400 Since focus left the "last name" box, the popup message appears.
500 Then your code sets focus back to the "last name" box.
600 GOTO 200

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2934
by: chris kramer | last post by:
i have an application that allows you to Select some text in a window, but no option to Copy it to the clipboard (nor does Ctrl-C or Shift-insert work, or right click etc..) i want to get these values somehow. below is the best posted method i have found online. if anyone can elaborate, as to how to implement such message passing (as a...
2
1602
by: Chris | last post by:
Dear all, Its IE again which is doing funny things to my page at http://www.bangor.ac.uk/webteam/uwb_template/blue/website/template.php Works as expected in Moz browsers - but IE makes the light blue box adjacent to the image slightly larger - and im going insane trying to work it out! Any spotters out there to help me from going...
27
2588
by: Mike P | last post by:
I will be passing my function a two dimensional array of varying length. Within that array is one data point, and the number of times it should loop through. So, for example, I might pass this to the function: example = new Array("A",2); example = new Array("Q",4); function loopIt(example);
4
2235
by: Norman Fritag | last post by:
Hi there, >>>__ 1020.83, 2305.22, 1176.86, 755.12, 123.41 __ 1976.1, 1325.99, 947, 718.03, 414.32 __ 1020.83, 1976.1, 352.5, 947, 718.03, 366.98 Their IDs were as ---------------------------------------------- __ 508671, 508789, 508850, 513108, 514552 __ 507960, 509289, 509149, 511454, 512759__ 508671, 507960, 510436, 509149, 511454,...
2
1905
by: DoomedLung | last post by:
Hey, I'm in the process of writing a function to check each element of a form isn't empty. I've come to a dead end.. Here is my function: function validateData(){
0
1289
by: jobs | last post by:
I have a many many pages with many formviews with many textboxes in them. The matrix of types of validation I need to do is a giant mess so please don't judge the code you are about to see - I don't want to use the new and native validatongroups .. well at least I want to know what I'm trying is not possible. I'm trying to loop through the...
1
2028
by: rose.kevin | last post by:
Hi I am trying to make a little tool tip box pop up when you hover the mouse over one of our custom filetypes in Windows explorer. And it is slowly driving me insane. I have a created a dll, with this as the code: using System; using System.IO;
3
1115
by: SAM | last post by:
ll a écrit : <script type="text/javascript"> function checkform( f ) // f is the form to check { var txt1 = 'Please make a selection for the Learning Outcome :', txt2 = '\nYour favorite Ice Cream flavor is a required field.'+ '\nPlease try again.'
2
1376
by: LayneMitch via WebmasterKB.com | last post by:
Hello. This is a basic quiz. Only about 3 questions. I'm having issue with the answer key which stays on a certain value regardless of acknowledging that you have the correct answer for the first and moving on to the next answer. Here's the code: <html><head><title>Problem7</title>
0
7546
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7830
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6071
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
784
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.