473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing for focus

I'd like to prevent a submit button from getting focus unless a particular
textbox or radio button is selected.

For example, if a user clicks anywhere within a form, the submit button is
focused and will submit whatever data is present if the user accidentally
presses Enter/Return. I would like to prevent this from happening unless
the user's cursor is within a textbox or the selection is on a radio button.
Is this possible? I believe this only happens with IE/Win.
Jul 20 '05 #1
2 5094
In article <O%*******************@bignews4.bellsouth.net>, "Mike Irwin"
<mi**@faroutfreakyshit.com> writes:
I'd like to prevent a submit button from getting focus unless a particular
textbox or radio button is selected.

For example, if a user clicks anywhere within a form, the submit button is
focused and will submit whatever data is present if the user accidentally
presses Enter/Return. I would like to prevent this from happening unless
the user's cursor is within a textbox or the selection is on a radio button.
Is this possible? I believe this only happens with IE/Win.


<input type="submit" onFocus="checkOtherField()" name="mySubmit">

function checkOtherField(){
if (!document.someForm.someObject.checked){
document.someForm.mySubmit.blur()
}
}

Or:

<input type="submit" onFocus="
if (!document.someForm.someObject.checked){this.blur( )}
" name="mySubmit">

Although, a better all around solution is to use the onSubmit of the form to
check it, instead of focus:

<form name="someForm" onSubmit="return checkOtherField()">

function checkOtherField(){
if (!document.someForm.someObject.checked){return false}
else{return true}
}
--
Randy
Jul 20 '05 #2

"HikksNotAtHome" <hi************@aol.com> wrote in message
news:20***************************@mb-m06.aol.com...
<input type="submit" onFocus="checkOtherField()" name="mySubmit">

function checkOtherField(){
if (!document.someForm.someObject.checked){
document.someForm.mySubmit.blur()
}
}

Or:

<input type="submit" onFocus="
if (!document.someForm.someObject.checked){this.blur( )}
" name="mySubmit">

Although, a better all around solution is to use the onSubmit of the form to check it, instead of focus:

<form name="someForm" onSubmit="return checkOtherField()">

function checkOtherField(){
if (!document.someForm.someObject.checked){return false}
else{return true}
}


Thanks for the reply, Randy. I believe this will work.
Jul 20 '05 #3

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

Similar topics

0
1717
by: Jonathan Allen | last post by:
We have found that our method of testing does not match traditional text-book methodologies. I decided to write a short white paper on it so that I could get your opinions. Does anyone else use...
8
1988
by: copyco | last post by:
I want to be able to test if my app's form has focus, (ie: not in background, behind other windows). How can I do this? I tried the Me.Focused, but that doesn't work. I think it's because a...
44
2793
by: John A. Bailo | last post by:
Dr. Dobbs has a /glowing/ article on Ruby on Rails this month. What do you guys think? Can it replace .net, php and java? And be the Open Source OOP web solution that is not bound to Sun or...
6
1576
by: Dick | last post by:
I’d appreciate some advice regarding unit tests. My questions are general in nature but (as usual) best conveyed via a (simplified) example: I have a table that contains two columns – the...
18
2360
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not...
24
2485
by: David | last post by:
Hi list. What strategies do you use to ensure correctness of new code? Specifically, if you've just written 100 new lines of Python code, then: 1) How do you test the new code? 2) How do...
11
2332
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have...
21
2476
by: =?ISO-8859-1?Q?Fad=A5?= | last post by:
Hello guys, I want to do kinda of an A/B split testing on a website I run. I just created a new version but I need to keep both version running and see which one will perform better. First, I'm...
0
7202
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,...
0
7086
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...
1
6991
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...
0
5578
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,...
1
5014
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...
0
4672
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...
0
3167
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...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
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...

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.