By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Testing for focus

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.