473,382 Members | 1,814 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,382 software developers and data experts.

How to control the tab key within onBlur

In my example the focus should only jump to textbox2 when you press the tab
key if '11' is in textbox1. If the value of textbox1 is not '11' than the
focus should be set back to textbox1. That works great in IE but in Mozilla
the cursor always jumps to textbox2 if you press the tab key even if the
value is not '11'.

<html>
<body>
<script type = 'text/javascript'>

function test(object) {
if (object.value == 11) {
return (true);
}
else {
return (false);
}
}

</script>
<form name = "my_form" action = "" method = "post" accept-charset =
"iso-8859-1">
<table id = "my_table" border = "1">
<tr>
<td>
<input type = "text" name = "my_textbox1" onBlur = 'if
(!test(document.my_form.my_textbox1))
{document.my_form.my_textbox1.focus();}'>
<input type = "text" name = "my_textbox2">
</td>
</tr>
</table>
</form>
</body>
</html>

What do I do wrong?
Stefan
Jan 26 '06 #1
4 8989

Stefan Mueller wrote:
In my example the focus should only jump to textbox2 when you press the tab
key if '11' is in textbox1. If the value of textbox1 is not '11' than the
focus should be set back to textbox1. That works great in IE but in Mozilla
the cursor always jumps to textbox2 if you press the tab key even if the
value is not '11'.

<html>
<body>
<script type = 'text/javascript'>

function test(object) {
if (object.value == 11) {
return (true);
}
else {
return (false);
}
}

</script>
<form name = "my_form" action = "" method = "post" accept-charset =
"iso-8859-1">
<table id = "my_table" border = "1">
<tr>
<td>
<input type = "text" name = "my_textbox1" onBlur = 'if
(!test(document.my_form.my_textbox1))
{document.my_form.my_textbox1.focus();}'>
<input type = "text" name = "my_textbox2">
</td>
</tr>
</table>
</form>
</body>
</html>

What do I do wrong?
Stefan

You do nothing wrong. Firefox has it all wrong.
It's a nasty bug that persists since the beginning.

Try this workaround:
change
document.my_form.my_textbox1.focus();
with
setTimeout("document.my_form.my_textbox1.focus();" ,1);

I think FF executes all the code on the onblur event and then sets the
focus on the new object, so it's something like:
select.onblur occures, it executes the function, sets the focus back to
the control and after that the onfocus of the newly focused object gets
triggered and it all happens in a singel process or something.
You simply delay the execution and it makes me wonder who has the bug,
IE or FF.
Anyway, it should work

Hope it helps.

Jan 27 '06 #2
> Try this workaround:
change
document.my_form.my_textbox1.focus();
with
setTimeout("document.my_form.my_textbox1.focus();" ,1);


Great, this works perfect.

Many thanks
Stefan
Jan 27 '06 #3
impaler wrote:
Stefan Mueller wrote:
In my example the focus should only jump to textbox2 when you press the
tab key if '11' is in textbox1. If the value of textbox1 is not '11' than
the focus should be set back to textbox1. That works great in IE but in
Mozilla the cursor always jumps to textbox2 if you press the tab key even
if the value is not '11'.
[...]
* function test(object) {
* * if (object.value == 11) {
Values of form controls are strings; this comparison works because of
implicit type conversion. Therefore, "11.000", "0x0B" and "0x0b" also
equal (`=='), but not strictly equal (`==='), 11. Unless this behavior
is wanted, it should be

if (object.value == "11") {
* * * return (true);
* * }
* * else {
* * * return (false);
* * }
* }
* * * <form name = "my_form" action = "" method = "post" accept-charset =
"iso-8859-1">
[...]
<input type = "text" name = "my_textbox1" onBlur = 'if
(!test(document.my_form.my_textbox1))
{document.my_form.my_textbox1.focus();}'>
<input type = "text" name = "my_textbox2">
[...]
</form>
[...]
What do I do wrong?
[...]

Please trim your quotes.
You do nothing wrong. Firefox has it all wrong.
It's a nasty bug that persists since the beginning.
It is not a bug. The `blur' event occurs when an element loses focus
(read: is about to lose focus), not when it has lost focus already.

<URL:http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-htmlevents>
Try this workaround:
change
document.my_form.my_textbox1.focus();
with
setTimeout("document.my_form.my_textbox1.focus();" ,1);


Eeek. The solution to prevent keyboard navigation in this case is, of
course, to cancel the keyboard event if the key pressed was the tab key
and test() returned `false'.

<input ... onkeydown="return test(this) || (event.keyCode != 9);">

WFM in Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20060110
Debian/1.5.dfsg-4 Firefox/1.5 Mnenhy/0.7.3.0.

However, this is not a Good Thing. Form data validity must not depend
entirely on DOM scripting, server-side testing is required. As for
form validation, it is better to do it before the form is submitted.
PointedEars
Jan 28 '06 #4
Many thanks for your additional information.

Stefan
Jan 28 '06 #5

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

Similar topics

1
by: neil S via DotNetMonster.com | last post by:
I have a custom control with a textbox and dropdown list. The dropdown list is hidden and acts as a data source for the textbox. When the user enters text in the textbox, an onKeyup event is...
0
by: Graham | last post by:
Is there a known bug with the CheckBox control? I have subclassed the control and I am trying to add an onclick attribute in the code behind. I've tried putting the Attributes.Add in the Page_Load,...
3
by: gg77 | last post by:
Hi, I don't have much knowledge of the table control. I am basically trying to use a table thats populated with data rows from a dataSet but currently things aren't working for me. below is...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
0
by: nkw | last post by:
I have two textboxes (tbox1, tbox2) in a step of Wizard control. I use javascript code to clear tbox2 when onblur occurring on tbox1: tbox1.Attributes = "javascript:var tbox2 =...
1
by: jjwhite01 | last post by:
I am working on a web form that contains a Calendar control with an image button that makes the calendar appear and disappear. However, I would like to set the visible property of the Calendar...
6
by: sudhashekhar30 | last post by:
hi i am trying to make a general function which is accepting control id as argument. mine code is like this. but it's not working. Javascript function function check(var obj) {alert(id of...
1
by: Duncan | last post by:
Hi all, I'm tearing my hair out on this! I have a simple ASP.NET 2 page with a TextBox control, in the PreRender I set ClientSide events:- Response.Attributes.Add("onchange",...
0
by: =?Utf-8?B?UGF1bA==?= | last post by:
I have an ajax calender control and when the user clicks off the control I would like to force a postback. It seems like possibly the onblur event may do it, but not sure if you can create a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...

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.