473,796 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with focus()

I thought this would be really simple, but i'm stumped. I'd like to validate some data without submitting the form, but i can't seem to get the focus to go back to the field with the bad data. I've stripped out most of the code just to illustrate the problem. In both IE and Mozilla, the focus still goes to the next element. This is .php generated.

<html><body><sc ript type="text/javascript">
var numAdults=5;
var numChildren=0;
function Check(element){
value=parseInt( element.value);
if(isNaN(value) || value<0 || value>99){
if(element.name =='txtNumAdults '){
element.value=n umAdults;
}else{
element.value=n umChildren;
}
element.focus() ;
return false;
}else{
//SetDirty(elemen t);
return true;
}
}
</script>
<form action="a1.php" method="POST" name="myFrm">
<table>
<tr><td align="right">< label>Adults:</label></td>
<td><input type="text" name="txtNumAdu lts" size="3" value="5" onChange="Check (this);" /></td></tr>
<tr><td align="right">< label>Children: </label></td>
<td><input type="text" name="txtNumChi ldren" size="3" value="0" onChange="Check (this);" /></td></tr>
</table></form></body></html>
Jul 20 '05 #1
4 1818
In article <32e1b9d1ee04f9 fe12d9c262201b5 0a9
@localhost.talk aboutprogrammin g.com>,
ch************* *****@nospamyah oo.com enlightened us with...
I thought this would be really simple, but i'm stumped. I'd like to validate some data without submitting the form, but i can't seem to get the focus to go back to the field with the bad data. I've stripped out most of the code just to illustrate the problem. In both IE and Mozilla, the focus still goes to the next element. This is .php generated.


I've seen it before. It has something to do with the onChange. I don't
remember exactly, but the solution was to change onChange to onBlur,
since change isn't fired until a text element loses focus anyway. (I
tried that with your code and it worked.)

Beware: if a user hits enter to submit the form, the onBlur won't fire.
Double up the validation so that onSubmit also validates, JIC.
--
--
~kaeli~
When two egotists meet, it's an I for an I.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
Kaeli,
Thanks. Using onBlur() fixes it for IE, but it still doesn't
work in Mozilla. What's also odd, is that if i add an
element.select( ); it will select the text, but the focus
still moves to the next element. Specs require that it works
in Mozilla also as many of the users have Linux workstations.
Any suggestions there?

Jul 20 '05 #3
Heh, i just found out that Mozilla had a new release yesterday
that is supposed to fix this. We shall see. Always nice to
know *I* wasn't doing anything wrong.

Jul 20 '05 #4
In article
<85************ *************** ***@localhost.t alkaboutprogram ming.com>,
ch************* *****@nospamyah oo.com enlightened us with...
Heh, i just found out that Mozilla had a new release yesterday
that is supposed to fix this. We shall see. Always nice to
know *I* wasn't doing anything wrong.


Good to know.
Unfortunately, my Unix users use NN7 and I haven't tested this in that
browser.
I ended up moving all my validation to onSubmit awhile ago when I had to
support that POS NN4.

--
--
~kaeli~
Support your local medical examiner: die strangely!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #5

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

Similar topics

0
1612
by: Dave | last post by:
Hi all, I have a problem with a query. (well, I actually have a few problems...) Here is my query. select FOCUS.SiteName, FOCUS.URL, OTWAdCars.* , REGION.SiteName as RegionSite, REGION.URL as RegionUrl from OTWSite as FOCUS right join OTWSite as REGION
4
2222
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for time and there is also a check on that. If time is empty return error message. Again the explorer returns error message and then shifts the focus to date field, again error message and focus goes to time and this story goes on and on, untill...
1
2480
by: Ricardo Garcia | last post by:
hi, i have the next situation: an index.html that has 2 frames (the main and the navigation bar) and the next problem (in IE, in Mozilla it works properly): when i start to scroll in the main window, it blurs, and of course, it finish scrolling, you must click to focus again. This is rather annoying. And i know that the other frame does not get the focus (i put an alert if it got, and it didn´t appear) I know is a problem of the focus...
2
3111
by: Peter Wright | last post by:
Hi all. Hopefully this should demonstrate the problem I'm having: http://flooble.net/~pete/focus-problem-demo/ (I'm testing it in Mozilla only, but I'm not sure if it's actually a Mozilla-only problem) I'm capturing the focus and blur events for the document, updating a
6
1705
by: nizar.jouini | last post by:
I have web page that contains two links. link "a" and link "b". When I click on "a" a small window should pop up. when I click on "b" another small window should pop up. So what you should see now is the base window which contains links "a" and "b" and two small pop-up windows "a" and "b". Now I can make the script to pop up "a" and "b" but the problem is that they're not shown at the same time. Any suggestions????
1
2245
by: avnrao | last post by:
Hi, I am facing a problem with control.focus (javascript). Here is the description of the issue. 1. I have 2 aspx files. on Aspx1 I have button named NewRow. Clicking on this, will redirect page to Aspx2 which has a Datagrid. PageLoad of Aspx2 displays the DataGrid with existing data filled in and shows a new row (set of text boxes) in the Footer Item. Now, when I set the focus by accessing the first text box in the Footer
1
5138
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
3
1387
by: ngkuhlmann | last post by:
I have a strange problem. I have a tab control with 5 tabs. When I click one of the tabs the tab show its information just fine, however when I test the focus, without moving and within a timer control, the focus returns a false. Any thoughts? TIA, Noral
3
4252
by: jan.loucka | last post by:
Hi, I looked around for this specific problem but could not find any answer - there's few things in VB but still nothing exactly like this so I'd appreciate any help. We're writing C# WinForm application that need to "silently" use another app (called MapInfo) within itself - the intention is to use this app (which is quite sophisticated mapping application) and add some other extra functionality to it. We have a dll so we can run the...
1
3121
by: Drelus | last post by:
I'm using an Ajax call to open a search box in the page and I want the focus to go to the box automatically. So, in the httpObject.responseText, I tried sending the following in addition to the search box markup: <script type="text/javascript"> document.getElementById('Message').focus(); </script> and, after writing the response using innerHTML, the originating Ajax function calls an eval function to enable the JavaScript, the critical...
0
9673
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7544
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.