473,796 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Directing the cursor to a input field

JW
hello everybody
I've got the following problem. I'm writing a form and I'm using javascript
to validate fields (i.e. numeric, not blank). When my scripts detects an
error I want it to put the cursor in the corresponding field.
I've tried the focus option, but that doesn't seem to work.
This is the code I'm using:

if (TestOk=="N")
{
alert('Veld mag niet leeg zijn');
veld.select();
veld.focus();
}

The veld.select() does select the error string, the focus, however doesm't
seem to work.
Anybody got a suggestion?
Thanks anyway
JW
Jul 23 '05 #1
7 6770
> The veld.select() does select the error string, the focus, however doesm't
seem to work.
Try document.Formna me.Fieldname.fo cus();

where 'Formname' is the name of your form and 'Fieldname' is the name of the
field you want to focus on.

If that doesn't work (it should though),what error message do actually get?

Thx
Stu
"JW" <ja*******@hotp op.com> wrote in message
news:%ayBc.4629 $%27.144199@zon net-reader-1... hello everybody
I've got the following problem. I'm writing a form and I'm using javascript to validate fields (i.e. numeric, not blank). When my scripts detects an
error I want it to put the cursor in the corresponding field.
I've tried the focus option, but that doesn't seem to work.
This is the code I'm using:

if (TestOk=="N")
{
alert('Veld mag niet leeg zijn');
veld.select();
veld.focus();
}

The veld.select() does select the error string, the focus, however doesm't
seem to work.
Anybody got a suggestion?
Thanks anyway
JW

Jul 23 '05 #2
JW
I've tried that format, but it didn't give me any results. I don't get any
error message, the cursor just doesn't go where I want it to.
JW

The veld.select() does select the error string, the focus, however doesm't seem to work.
Try document.Formna me.Fieldname.fo cus();

If that doesn't work (it should though),what error message do actually

get?
Thx
Stu

Jul 23 '05 #3
Can you supply your full code? (JS and forms html), what browsers are you
using too?

Stu

"JW" <ja*******@hotp op.com> wrote in message
news:pLBBc.4645 $%27.145901@zon net-reader-1...
I've tried that format, but it didn't give me any results. I don't get any error message, the cursor just doesn't go where I want it to.
JW

The veld.select() does select the error string, the focus, however doesm't seem to work.


Try document.Formna me.Fieldname.fo cus();

If that doesn't work (it should though),what error message do actually

get?

Thx
Stu


Jul 23 '05 #4
JW
The script I'm using is like the following one. It has to work in IE. Other
browsers are not important for now, because it's meant as a field check for
a business application.
When you use the buttons to set focus to the appropriate field the function
used to setfocus works perfectly.
When the NotEmpty function is triggered by leaving the input field the focus
stays on the next selected field.
When you want to see this code working visit :
http://home.zonnet.nl/janwouter/script/focus.html

<html>
<head>
<script lang=javascript >
function NotEmpty(veld)
{
TestOk="N";
invoer=veld.val ue.toString();
for(var i=0;i<invoer.le ngth;i++)
{
var teken =invoer.charAt( i);
if (teken != ' ')
{
TestOk="J";
i=invoer.length ;
}
}
if (TestOk=="N")
{
/* alert('Veld mag niet leeg zijn');*/
veld.value="Fie ld may not be empty !!";
focusonfield(ve ld);
}
} /*einde functie NotEmpty*/

function focusonfield(fi eld)
{

if (field.name=="i np1")
{document.form1 .inp1.focus()}

if (field.name=="i np2")
{document.form1 .inp2.focus()}

if (field.name=="i np3")
{document.form1 .inp3.focus()}

}
</script>
</head>
<body>
<form name ="form1">
<input name="inp1" value="veld1" onchange="NotEm pty(this)";/>
<input name="inp2" value="veld2" onchange="NotEm pty(this)";/>
<input name="inp3" value="veld3" onchange="NotEm pty(this)";/>
<br/>
<button name="but1" onclick="focuso nfield(form1.in p1)">veld1</button>
<button name="but2" onclick="focuso nfield(form1.in p2)">veld2</button>
<button name="but3" onclick="focuso nfield(form1.in p3)">veld3</button>
</form>
</body>

"Stuart Palmer" <tr**********@y oucant.com> schreef in bericht
news:2j******** *****@uni-berlin.de...
Can you supply your full code? (JS and forms html), what browsers are you
using too?

Stu

Jul 23 '05 #5
Lee
JW said:

The script I'm using is like the following one. It has to work in IE. Other
browsers are not important for now, because it's meant as a field check for
a business application.
When you use the buttons to set focus to the appropriate field the function
used to setfocus works perfectly.
When the NotEmpty function is triggered by leaving the input field the focus
stays on the next selected field.


The problem seems to be that moving focus to the next field occurs
after the onChange event has completed and it can't be cancelled.

A hack to work around this is to let the focus move to the next
field, but then bring it back to where you want it by scheduling
focus to return after a short delay:

function focusonfield(fi eld)
{
var fieldRef="docum ent.forms['" + field.form.name
+"'].elements['" + field.name+"']";
setTimeout(fiel dRef+".select() ;"+fieldRef+".f ocus()",10);
}

Jul 23 '05 #6
JW
Makes sense. I'm gonna try it today and let you know the results.
Thanks
JW
The problem seems to be that moving focus to the next field occurs
after the onChange event has completed and it can't be cancelled.

Jul 23 '05 #7
JW
It worked great! Thanks for your help.
JW
Makes sense. I'm gonna try it today and let you know the results.
Thanks
JW
The problem seems to be that moving focus to the next field occurs
after the onChange event has completed and it can't be cancelled.


Jul 23 '05 #8

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

Similar topics

6
4017
by: Gonzosez | last post by:
When a page is opened is there a way to set focus of the cursor to a named input. I want the cursor to be in the input box when the page is opened. Thanks
9
8247
by: Gary Holt | last post by:
We have a problem demonstrated by the following HTML document. To see the problem type HV in the first field then use the mouse cursor to click into the Staff code input box. You will find that the cursor has ended up in the prompt field rather than the input. I think it is due the table dynamically resizing when the description is added to the second cell, so where your cursor clicked no longer contains the location of the input box. ...
5
2132
by: Rune Runnestø | last post by:
How do I focus the cursor in the input field 'numberField' when accessing this jsp-file (or html-file) ? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head>
7
8667
by: William Gill | last post by:
I have been trying to pass parameters as indicated in the api. when I use: sql= 'select * from %s where cusid = %s ' % name,recID) Cursor.execute(sql) it works fine, but when I try : sql= 'select * from %s where cusid like %s ' Cursor.execute(sql,(name,recID))
4
1938
by: Filips Benoit | last post by:
Dear All, How to clearly show the active (cursor) field. A very large form having about 100 inputfields. After pausing input the user must see a once where the cursor is! Thanks, Filip
1
1440
by: AA Arens | last post by:
(1) When I want the data in the datafield starts with the first character forcedly uppercased, I use the input mask >L<, followed by ?????. When entering the data, the field is marked with underscores (____), But I do not want to see them. (2) When I click on an emtpy field with a mouse, the cursor stays not in the first position.
11
3315
idsanjeev
by: idsanjeev | last post by:
how can set cursor location everytime when page is open cursor goes to auto in input field and chake when click on submit lenth of input field
3
4620
by: Klaus Brune | last post by:
Hello all, When one tabs through a form (specifically, in Firefox), all the text in a field is automatically selected. What I'm looking for is a way to put a function (in onFocus perhaps) that will automatically move to the END of the existing text (a blinking cursor). Yes, I've Googled, but cannot seem to locate just what I'm looking for.
0
9680
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, 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...
0
9528
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
10456
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...
1
10174
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
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
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
4118
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
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.