473,804 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tab and focus

If in the textarea (textarea3), the value is not "abc", and the user
uses "Tab" to go to the next textarea (textarea4), it will alert an
error message...and the focus will return to the textarea (textarea3)
again...
It works in Internet Explorer, however in firefox it does not work?
Anyway have any ideas why & how?

Here is the source,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitl ed Document</title>
</head>
<script>
function checkMe(id)
{
obj = document.getEle mentById(id);
if (obj.value != "")
{
var text = "abc";
if (obj.value != text)
{
alert("WRONG!!! ")
obj.focus();
obj.select();
}
}
}
</script>
<body>
<table width="200" border="0">
<tr>
<td><textarea id="textarea3" name="textarea3 "
onblur="checkMe ('textarea3')"> </textarea>
</td>
<td><textarea id="textarea4" name="textarea4 "
onblur="checkMe ('textarea4')"> </textarea></td>
</tr>
</table>
</body>

Dec 1 '05 #1
9 2417
fidodido wrote:
If in the textarea (textarea3), the value is not "abc", and the user
uses "Tab" to go to the next textarea (textarea4), it will alert an
error message...and the focus will return to the textarea (textarea3)
again...
It works in Internet Explorer, however in firefox it does not work?
Anyway have any ideas why & how?

Here is the source,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
IE does not support XHTML (application/xhtml+xml) at all. Sending XHTML as
text/html is harmful; XHTML 1.0 Appendix C is informative, not normative.

<URL:http://hixie.ch/advocacy/xhtml>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/> ^
No _XML_ parser will care about that; it is far too late because the
document has already been parsed.
<title>Untitl ed Document</title>
<URL:http://www.w3.org/QA/Tips/good-titles>
</head>
<script>
This is neither Valid HTML nor Valid XHTML. The `script' element, which
requires a `type' attribute value, must be child element of the `head'
or the `body' element. Non-conforming UAs like IE ignore that, Firefox
probably does not.

<URL:http://validator.w3.or g/>
function checkMe(id)
{
obj = document.getEle mentById(id);
All methods of host objects should be feature-tested on
run-time before being called.

<URL:http://www.pointedears .de/scripts/test/whatami>, §2.
if (obj.value != "")
getElementById( ) returns either an object reference, null
or something undefined. It never returns the empty string,
and both {} != "" and null != "", so the condition will be
always true (read: is completely useless).

<URL:http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-getElBId>

Furthermore, there is no need for gEBI here.
{
var text = "abc";
No need for this variable.
if (obj.value != text)
if (obj.value != "abc")
{
alert("WRONG!!! ")
obj.focus();
obj.select();
Again neither method of the host environment is feature-tested before
called.
}
}
}
</script>
<body>
<table width="200" border="0">
<tr>
<td><textarea id="textarea3" name="textarea3 "
onblur="checkMe ('textarea3')"> </textarea>
</td>
<td><textarea id="textarea4" name="textarea4 "
onblur="checkMe ('textarea4')"> </textarea></td>
</tr>
</table>
</body>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>...</title>

<script type="text/javascript">
function isMethodType(s)
{
return (s == "function" || s == "object");
}

function checkMe(o)
{
if (o)
{
if (o.value != "abc")
{
alert("Wrong!") ;

if (isMethodType(t ypeof o.focus))
{
o.focus();
}

if (isMethodType(t ypeof o.select))
{
o.select();
}
}
}
}
</script>
</head>

<body>
<table border="0">
<tr>
<td><textarea name="textarea3 " rows="23" cols="42"
onblur="checkMe (this)"></textarea></td>
<td><textarea name="textarea4 " rows="23" cols="42"
onblur="checkMe (this)"></textarea></td>
</tr>
</table>
</body>
</html>

(Perhaps the `table' element is not appropriate here -- is it really
tabular data? --, you should consider CSS for layout.)

However, being controlled this way can be unnerving for the user. If
there is a `form' element to be submitted, it is usually sufficient to
check on submit; if that does not apply or suffice here, you should
use means different from alert() to notify the user, perhaps the value
of a third form control without name (so that its name and value are
not submitted).
PointedEars
Dec 1 '05 #2
Thomas 'PointedEars' Lahn wrote:
if (obj.value != "abc")
{
alert("WRONG!!! ")


CAUTION: In my Firefox 1.0.7/Linux, alert() removes focus from the calling
window, hence from the target `textarea' element which fires the `blur'
event and so results in the execution of alert() again -- causing _another_
alert window. This also happens every time focus is tried to be moved away
from the calling window to other application windows (like the compose
window of the newsreader I am using now).

The only way to break this deadlock is to kill the browser process!
PointedEars
Dec 1 '05 #3
fidodido wrote:
If in the textarea (textarea3), the value is not "abc", and the user
uses "Tab" to go to the next textarea (textarea4), it will alert an
error message...and the focus will return to the textarea (textarea3)
again...
It works in Internet Explorer, however in firefox it does not work?
Anyway have any ideas why & how?

Here is the source,

[..snip..]
on which PointedEars replied:

However, being controlled this way can be unnerving for the user. If
there is a `form' element to be submitted, it is usually sufficient to
check on submit; if that does not apply or suffice here, you should
use means different from alert() to notify the user, perhaps the value
of a third form control without name (so that its name and value are
not submitted).

I vehemently agree with PointedEars here: forcing a users action in this way
is really obnoxious. From an interaction-design POV this is a serious fault
and the user experience will suffer greatly. In plain language: your users
will hate you.

You might want to consider this:
if user tabs away from field without a valid entry change the color/look of
the formfield to draw attention to it. In the mean time you could disable
the submit button untill the appropriate data is filled in. Do however
notify the user that valid data is needed to enable the submit button. For
instance by using another, readonly, formfield that displays the
errormessage in stead of an alert..

(yeah, I know, not really scripting-help but I thought I'd bring this up
regardless..)
Patrick.
--

Patrick Kanne - Webmaniac
petnews _AT_ quaint _DOT_ info
http://patrick.quaint.info
Dec 1 '05 #4
Thomas 'PointedEars' Lahn wrote:
fidodido wrote:

If in the textarea (textarea3), the value is not "abc", and the user
uses "Tab" to go to the next textarea (textarea4), it will alert an
error message...and the focus will return to the textarea (textarea3)
again...
It works in Internet Explorer, however in firefox it does not work?
Anyway have any ideas why & how?

[...]
However, being controlled this way can be unnerving for the user. If
there is a `form' element to be submitted, it is usually sufficient to
check on submit; if that does not apply or suffice here, you should
use means different from alert() to notify the user, perhaps the value
of a third form control without name (so that its name and value are
not submitted).


Agree completely.

But the OP's question is not answered - why doesn't focus, when asked,
go to the control that is supposed to receive it? Use a button to
command the pesky focus and it obeys, but have it told what to do onblur
and it ignores the request.

The use of setTimeout 'fixes' the behaviour, but at the cost of a rather
ugly kludge:
...
if (isMethodType(t ypeof o.focus))
{
setTimeout(func tion(){o.focus( );}, 0);
}
...
Riddle me that Thomas - or should I be downloading Firefox 1.5? :-)
--
Rob
Dec 1 '05 #5
RobG wrote:
But the OP's question is not answered - why doesn't focus, when asked,
go to the control that is supposed to receive it?
It does here.
Use a button to command the pesky focus and it obeys, but
have it told what to do onblur and it ignores the request.
It does not ignore anything here[1] on Valid markup. Which is
actually a Bad Thing, see news:39******** ********@Pointe dEars.de

[1] Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922
Firefox/1.0.7 (Debian package 1.0.7-1) Mnenhy/0.7.2.0
The use of setTimeout 'fixes' the behaviour, but at the cost of a rather
ugly kludge:

...
if (isMethodType(t ypeof o.focus))
{
setTimeout(func tion(){o.focus( );}, 0);
}
...

Riddle me that Thomas - or should I be downloading Firefox 1.5? :-)


Pardon me?
PointedEars
Dec 1 '05 #6
Thomas 'PointedEars' Lahn wrote:
RobG wrote:

[...]

Riddle me that Thomas - or should I be downloading Firefox 1.5? :-)

Pardon me?


For me, the alert is presented and when cleared, the focus moves on
(Firefox 1.0.7 on Windows XP Pro SP1).

I just download Firefox 1.5 and got the same result.

--
Rob
Dec 1 '05 #7
RobG wrote:
Thomas 'PointedEars' Lahn wrote:
RobG wrote:
[alert() fires blur event for form controls]
Riddle me that Thomas - or should I be downloading Firefox 1.5? :-)

Pardon me?


For me, the alert is presented and when cleared, the focus moves on
(Firefox 1.0.7 on Windows XP Pro SP1).


Interesting. It appears that the behavior depends on the window manager or
window framework used. So that approach cannot be recommended for the Web.
PointedEars
Dec 1 '05 #8
Thomas 'PointedEars' Lahn wrote:
RobG wrote:

Thomas 'PointedEars' Lahn wrote:
RobG wrote:

>[alert() fires blur event for form controls]

Riddle me that Thomas - or should I be downloading Firefox 1.5? :-)

Pardon me?


For me, the alert is presented and when cleared, the focus moves on
(Firefox 1.0.7 on Windows XP Pro SP1).

Interesting. It appears that the behavior depends on the window manager or
window framework used. So that approach cannot be recommended for the Web.


It's a reported bug.

<URL: https://bugzilla.mozilla.org/show_bug.cgi?id=312466 >
Sorry about the delay in responding, I accidentally posted it as a
response to another thread.
--
Rob
Dec 1 '05 #9
setTimeout() works...
I will use that then....

Thanks a lot.... :)

Dec 2 '05 #10

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

Similar topics

4
2223
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...
2
3112
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
3
6898
by: VA | last post by:
t=document.getElementById('mytable') is a HTML table with some input fields in its cells Why doesnt t.getElementsByTagName('tr').firstChild.focus; put the focus on that text field? It doesnt give any errors, the focus just doesnt change.
17
3868
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a record to the subform (based on the value of the combo box) and requeries the subform control. I want the focus to return to the combo box on the main form when it's done, but I can't get it to do so if the user enters a value and presses Enter...
1
2246
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
4
3954
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several textboxes and a checkbox. The behaviour I want from my app is as follows:- When the textbox (which is prior in tab order to the tab control) has been filled with a certain length of text by the user, the focus is
11
7359
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz 1.7.12 (linux kubuntu). It does work with konqueror. It seems to work with firefox on windows but not with IE (not completly sure though).
7
11934
by: Dave Booker | last post by:
I am using a WebBrowser object in my .NET 2.0 application, but it is not shown to the user. Every time a timer event triggers it to perform a m_WebBrowser.Navigate() I get that classic IE 'click' and it steals the focus from the user's current application. How can I prevent the hidden WebBrowser from stealing focus? (And better yet can I even suppress that click?_
4
68053
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between these forms that may make one succeed and another fail? In particular, this.window.focus() fails in Opera 9.10 with an "object not found", and windows.focus() succeeds in Opera 9.10, Firefox 2.02, and IE 7.
3
5200
by: jp2express | last post by:
I have several applications that use panels as screens, but I can *not* seem to set the focus for a Textbox. Panel1.BringToFront() Panel1_Textbox.Focus() ' do something with a control on Panel1 Panel2.BringToFront() Panel2_Textbox.Focus() ' do something with a control on Panel2
0
9595
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
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
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
10354
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9175
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6867
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();...
1
4313
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
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
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.