All,
I'm having a problem returning focus back to an input field in Netscape. The
code works in IE and Opera but not in netscape6+.
Basically I have a function that is called upon exiting a form field, if the
value validates properly it returns true and calls another function, if it
doesn't validate the field it returns false and I want to give focus back to
the sender and highlight all of the text in the field.
The problem is that while IE and opera return the curser back to the field -
Netscape ignores the focus statement (I still can't find any examples as to
how to return the curser and highlight the text in the field).
Any suggestions as to what I'm doing wrong will be appreciated.
CES
function fExitField(send er){
returnedValue = fValidateData(s ender);
if(returnedValu e == true){ //
fRemoveAsterisk (sender);
}
if(returnedValu e == false){
document.forms[fGetFormName(se nder)].elements['id_'
+ sender].focus(); // FYI I have multiple forms an the page -
fGetFormName(se nder) returns the name of the form that contains the element.
alert("Improper Format");
}
}
This is an example of my tag structure:
<input id="id_cName" name="cName" type="text" maxlength="50"
onFocus="fEnter Field('cName')" onKeyDown="fKey Press('cName')"
onKeyUp="fKeyPr ess('cName')" onBlur="fExitFi eld('cName')" tabindex="1" /> 10 6723
Js Almighty,
Anyone monitors this group?
1.) ID vs. NAME
2.) Full DOM path by 3W vs. Shortened Path by IE
Cane we make a good FAQ on it?
With a daily repost?
"CES" <No**@noSpam.co m> writes: I'm having a problem returning focus back to an input field in Netscape. The code works in IE and Opera but not in netscape6+.
Basically I have a function that is called upon exiting a form field, if the value validates properly it returns true and calls another function, if it doesn't validate the field it returns false and I want to give focus back to the sender and highlight all of the text in the field.
Mozilla/Netscape 6+ has a quirk: If you try to change the focus, it triggers
the onblur event *before* changing the focus. So when you set focus in the
onblur handler, the real focus change happens afterwards anyway.
A known solution is to delay the setting of the focus, i.e., instead
of foo.focus(), you do
setTimeout(func tion(){foo.focu s();},10);
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
CES said: All, I'm having a problem returning focus back to an input field in Netscape. The code works in IE and Opera but not in netscape6+. Basically I have a function that is called upon exiting a form field, if the value validates properly it returns true and calls another function, if it doesn't validate the field it returns false and I want to give focus back to the sender and highlight all of the text in the field. The problem is that while IE and opera return the curser back to the field - Netscape ignores the focus statement (I still can't find any examples as to how to return the curser and highlight the text in the field). Any suggestions as to what I'm doing wrong will be appreciated.
CES function fExitField(send er){
returnedValue = fValidateData(s ender);
if(returnedValu e == true){ //
fRemoveAsterisk (sender);
}
if(returnedValu e == false){
document.forms[fGetFormName(se nder)].elements['id_' + sender].focus(); // FYI I have multiple forms an the page - fGetFormName(s ender) returns the name of the form that contains the element.
alert("Improper Format");
}
}
1. Don't pass the name of the field around. Pass a reference
to it, and you won't have to worry about which form it's in.
2. Don't validate onBlur. There are too many unexpected things
that can cause a field to lose focus. Being forced to click
the OK button of an alert, for instance.
3. Never test a logical value for equality to true or false,
and certainly never test against both cases.
If it's true, it's true, otherwise, it's false.
4. Don't name all of your functions with a lowercase "f" prefix.
If it has parentheses after it, it's a function.
function fExitField(send er){
if(fValidateDat a(sender)){
fRemoveAsterisk (sender);
}else{
alert("Improper Format");
sender.focus();
}
}
<input id="id_cName" name="cName" type="text" maxlength="50"
onFocus="fEnter Field(this)" onKeyDown="fKey Press(this)"
onKeyUp="fKeyPr ess(this)" onChange="fExit Field(this)" tabindex="1" />
On 1 Dec 2003 15:38:58 -0800, Lee <RE************ **@cox.net> wrote: 2. Don't validate onBlur. There are too many unexpected things that can cause a field to lose focus. Being forced to click the OK button of an alert, for instance.
So how would you do it? Personally, as a user, I'd prefer to get
feedback step-by-step, rather than waiting until I get to the end of the
form.
What arguably is a problem is the combination of onBlur and validation
results via an alert box. If one is doing onBlur validation, it's better
to write error messages in the HTML, next to the field concerned. Leave
the alert boxes until one gets to onsubmit.
I'm also not sure that forcing the focus back to the field concerned is
a good idea with onBlur validation. Maybe a colleague is looking up
(say) our contract number while I get on with filling in the rest of the
form. I don't want to be blocked from doing so.
--
Stephen Poley
Stephen Poley said: On 1 Dec 2003 15:38:58 -0800, Lee <RE************ **@cox.net> wrote:
2. Don't validate onBlur. There are too many unexpected things that can cause a field to lose focus. Being forced to click the OK button of an alert, for instance.
So how would you do it? Personally, as a user, I'd prefer to get feedback step-by-step, rather than waiting until I get to the end of the form.
use onChange, instead of onBlur
JRS: In article <bq*********@dr n.newsguy.com>, seen in
news:comp.lang. javascript, Lee <RE************ **@cox.net> posted at Mon,
1 Dec 2003 15:38:58 :- 1. Don't pass the name of the field around. Pass a reference to it, and you won't have to worry about which form it's in.
In the page I'm currently working on, there can be several forms with
the same structure. Here it is convenient to use the field name
qualified by the form name; thus, identical parts of different forms ban
use the same name.
There is much to be said for limiting the scope of identifiers; for
example, it reduces the risk of inadvertently writing to the wrong form.
4. Don't name all of your functions with a lowercase "f" prefix. If it has parentheses after it, it's a function.
If it has a left parenthesis, it needs to be a function. That means
that *either* it is a function, *or* it is a mistake. The f-notation
may help in avoiding the latter.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
On 2 Dec 2003 09:14:53 -0800, Lee <RE************ **@cox.net> wrote: Stephen Poley said: On 1 Dec 2003 15:38:58 -0800, Lee <RE************ **@cox.net> wrote:
2. Don't validate onBlur. There are too many unexpected things that can cause a field to lose focus. Being forced to click the OK button of an alert, for instance.
So how would you do it? Personally, as a user, I'd prefer to get feedback step-by-step, rather than waiting until I get to the end of the form.
use onChange, instead of onBlur
Yes, I suppose so. The one thing you can't then do is replace the small
civilised "required" marker with a bold red "ERROR - You must enter
this" marker when the user tabs through a field without entering
anything. But perhaps that's not important enough to be worth worrying
about.
--
Stephen Poley
Stephen Poley said: On 2 Dec 2003 09:14:53 -0800, Lee <RE************ **@cox.net> wrote:
Stephen Poley said: On 1 Dec 2003 15:38:58 -0800, Lee <RE************ **@cox.net> wrote:
2. Don't validate onBlur. There are too many unexpected things that can cause a field to lose focus. Being forced to click the OK button of an alert, for instance.
So how would you do it? Personally, as a user, I'd prefer to get feedback step-by-step, rather than waiting until I get to the end of the form.
use onChange, instead of onBlur
Yes, I suppose so. The one thing you can't then do is replace the small civilised "required" marker with a bold red "ERROR - You must enter this" marker when the user tabs through a field without entering anything. But perhaps that's not important enough to be worth worrying about.
Yes. Consider how annoying it is to tab down to the field whose value
you happen to have in your paste buffer at the moment, only to have
every field along the way scream at you.
On 2 Dec 2003 13:16:00 -0800, Lee <RE************ **@cox.net> wrote: Stephen Poley said: On 2 Dec 2003 09:14:53 -0800, Lee <RE************ **@cox.net> wrote:
Stephen Poley said:
On 1 Dec 2003 15:38:58 -0800, Lee <RE************ **@cox.net> wrote:
>2. Don't validate onBlur. There are too many unexpected things > that can cause a field to lose focus. Being forced to click > the OK button of an alert, for instance.
So how would you do it? Personally, as a user, I'd prefer to get feedback step-by-step, rather than waiting until I get to the end of the form.
use onChange, instead of onBlur
Yes, I suppose so. The one thing you can't then do is replace the small civilised "required" marker with a bold red "ERROR - You must enter this" marker when the user tabs through a field without entering anything. But perhaps that's not important enough to be worth worrying about.
Yes. Consider how annoying it is to tab down to the field whose value you happen to have in your paste buffer at the moment, only to have every field along the way scream at you.
Granted. You've convinced me.
--
Stephen Poley This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: chirs |
last post by:
Hi,
I want to put a value in a cookie. The following code does not work.
It does not store the box1.value in the cookie. How can I fix it?
<input type="text" name="box1" onblur=document.cookie="user=" +
box1.value>
Chris
|
by: iinet |
last post by:
How can i set in my css a min width for input elements, but leave the max
size dynamic?
Ben
|
by: TR |
last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox
with a nested label?
This is the label of the
checkbox that wraps beneath it
I'd prefer it looked like this, with a flush left margin:
|
by: owen |
last post by:
I have an <input> box and i want to disable the apostrophe ( ' ) key, so
when you press it, no character appears in the input box. All other keys
should work ok.
I can trap the keypress event using "onkeypress=myKeypressHandler()" but,
beyond that, I'm stuck. I forget how to detect what key was pressed or how
to "null it out".
I'm using IE6 and users will be IE5.0 upward ONLY (trust me on this, suffice
to say it's not a website but...
|
by: Rocio |
last post by:
I have a html button created with
<input type="submit" id="btnPayNotices" value="Pay Notices" />
now I need to trap the click event at the server side.
Yes, this button had to be created with plain html, not with asp.net
how can i do this ?
| |
by: Bart van Deenen |
last post by:
Hi all
I have a form with a couple of input fields, embedded within spans. I am
using script.aculo.us for dragging and dropping, and want to reorder the
input fields that way. The input fields are display:inline because I
want them all on the same line.
Does anyone know of a smart trick to be able to drag these input fields?
Just setting their disabled attribute doesn't work, because then they
get no events. Not setting disabled just...
|
by: Rick |
last post by:
I'm trying to make an input tag visible or hidden based on the value of
another input tag, so that when the 1st input tag is changed in anyway, the
2nd input tag will become visible.
Thanks in advance,
Rick
|
by: Sreenath Rao Nellutla |
last post by:
Hai all,
I am trying to create dropdown calendar control with HTML input control by writing JavaScript. But while executing I am getting the error as "Error on Page" on the status bar of the browser. I wrote the following code in the HTML code for the web form:
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="calendar.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>...
|
by: test9991014 |
last post by:
Hi folks,
I've got something like this:
<table>
<tr>
<td>1</td>
<td align=center>
<input type=text>
</td>
|
by: Zhang Weiwu |
last post by:
hello.
Is it possible to design CSS in the way that content in <inputare not
visible in print out (a.k.a. value of <inputnot visible) while the
border remain visible?
trial:
input {
border: thin solid black;
|
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...
| |
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,...
|
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...
|
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,...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |