473,791 Members | 3,137 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 5116
In article <O%************ *******@bignews 4.bellsouth.net >, "Mike Irwin"
<mi**@faroutfre akyshit.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="checkO therField()" name="mySubmit" >

function checkOtherField (){
if (!document.some Form.someObject .checked){
document.someFo rm.mySubmit.blu r()
}
}

Or:

<input type="submit" onFocus="
if (!document.some Form.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="retur n checkOtherField ()">

function checkOtherField (){
if (!document.some Form.someObject .checked){retur n 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="checkO therField()" name="mySubmit" >

function checkOtherField (){
if (!document.some Form.someObject .checked){
document.someFo rm.mySubmit.blu r()
}
}

Or:

<input type="submit" onFocus="
if (!document.some Form.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="retur n checkOtherField ()">

function checkOtherField (){
if (!document.some Form.someObject .checked){retur n 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
1778
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 this method? If so, what the heck is it called? Do you think it would work in other projects, or did we just luck out? Jonathan Allen *****************
8
2006
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 control within the form actually has focus, so the Me.Focused would return false. Thanks!
44
2866
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 MS? http://media.rubyonrails.org/presentations/pursuitofbeauty.pdf
6
1597
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 name of a PC and the date/time that an event took place. I have a stored procedure that accepts two date arguments – a start date/time and an end date/time. It returns a list of PC’s and the number of times the event took place within the...
18
2401
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 that great. One of the cons of ASP & Javascript is that they're both interpreted, which means one has twice the amount of work to do interms of syntax checking & semantic/runtime checking. Another bad thing is that ASP & Javascript doesn't have...
24
2528
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 you ensure that the code will work correctly in the future? Short version:
11
2382
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 realized that despite suggestions to use DHTML-based modal dialogs are very common? there is not a single fully functional reliable copyright-free cross-browser alternative to say MsgBox (VBScript) or showModalDialog (IE). This way such suggestions up to...
21
2527
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 not sure if I'm in the right group. How can I randomly let a user enter from the index.php page and keep the same URL. So the splitting is being done in the backend, I don't want the users to see for example in the url /new/index.php and /...
0
9515
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
10427
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
9995
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...
0
9029
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...
1
7537
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
6776
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();...
0
5431
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...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2916
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.