473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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><script 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=numAdults;
}else{
element.value=numChildren;
}
element.focus();
return false;
}else{
//SetDirty(element);
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="txtNumAdults" size="3" value="5" onChange="Check(this);" /></td></tr>
<tr><td align="right"><label>Children:</label></td>
<td><input type="text" name="txtNumChildren" size="3" value="0" onChange="Check(this);" /></td></tr>
</table></form></body></html>
Jul 20 '05 #1
4 1785
In article <32e1b9d1ee04f9fe12d9c262201b50a9
@localhost.talkaboutprogramming.com>,
ch******************@nospamyahoo.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.talkab outprogramming.com>,
ch******************@nospamyahoo.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
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...
4
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...
1
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...
2
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...
6
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...
1
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...
1
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...
3
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...
3
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.