472,353 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 1713
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,...
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...
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...
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...
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...
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...
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...
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...
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...
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.