473,385 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Radio Button and focus

I have a page where I utilise the left and right cursor keys to change an
image, also on this page is a groups of radio buttons, unfortunately when a
radio button is clicked the focus for the cursor keys goes to the radio
buttons and any subsequent cursor key presses scroll through the radio
buttons.

How do I take focus away from the radio buttons after they have been clicked
?
Dec 20 '05 #1
16 3599

Stuart wrote:
I have a page where I utilise the left and right cursor keys to change an
image, also on this page is a groups of radio buttons, unfortunately when a
radio button is clicked the focus for the cursor keys goes to the radio
buttons and any subsequent cursor key presses scroll through the radio
buttons.

How do I take focus away from the radio buttons after they have been clicked
?


You can use the blur method. For example:

js:

function focusOff(radioObj)
{
radioObj.blur();
}

html:

<input type = "radio" onclick = "focusOff(this)"/>text

Note: if you have a group of radio buttons, then you'll have to set the
even handler for each of them. You can see how quickly inefficient
this can become.

Dec 20 '05 #2
Stuart wrote:
I have a page where I utilise the left and right cursor keys to change an
What are 'left and right cursor keys'? Do you mean mouse buttons? Not
everyone has left and right mouse buttons. Not everyone navigates with
a mouse, or even has a mouse.

Can users change images if scripting is disabled or not available?

image, also on this page is a groups of radio buttons, unfortunately when a
radio button is clicked the focus for the cursor keys goes to the radio
buttons and any subsequent cursor key presses scroll through the radio
buttons.
Seems your UI logic is flawed.

How do I take focus away from the radio buttons after they have been clicked


Presumably some other element has focus when you detect the 'cursor
keys'. Set that element to have focus whenever a radio button is
clicked by putting an onclick event on each radio button:

<input type="radio"
onclick="if(someOtherElement.focus)someOtherElemen t.focus()"
... >
The UI sounds confusing and overly complicated.
--
Rob
Dec 20 '05 #3
web.dev wrote:
Stuart wrote:
I have a page where I utilise the left and right cursor keys to change an
image, also on this page is a groups of radio buttons, unfortunately when
a radio button is clicked the focus for the cursor keys goes to the radio
buttons and any subsequent cursor key presses scroll through the radio
buttons.

How do I take focus away from the radio buttons after they have been
clicked ?
You can use the blur method.


But you should not, see below.
For example:

js:

function focusOff(radioObj)
{
radioObj.blur();
}
Radio/HTMLInputElement objects are host objects, so you should
test for its methods before you call them.

function isMethodType(s)
{
return (s == "function" || s == "object");
}

function focusOff(radioObj)
{
if (radioObj && isMethodType(typeof radioObj.blur))
{
radioObj.blur();
}
}
html:

<input type = "radio" onclick = "focusOff(this)"/>text ^
This is more XHTML than it is HTML. (In HTML that is equivalent
to

<input type = "radio" onclick = "focusOff(this)">&gt;text

but only few user agents support HTML SHORTTAG properly.)

And IE does not support XHTML (instead it renders falsely error-corrected
HTML if XHTML documents are served as text/html), so there is no use in
attempting to feed the former with the latter, and no advantage of XHTML
over HTML here whatsoever. Use Valid HTML 4.01 instead:

<input type="radio" id="radio0_1" onclick="focusOff(this)"<label for="radio0_1">text</label>
However, using focusOff() here inevitably makes the form unusable for users
that have client-side script support present but do not want or cannot use
a pointing device. Clearly a Bad Thing, and one that can be avoided.
Note: if you have a group of radio buttons, then you'll have to set the
even handler for each of them. [...]


No, you could use a parent `fieldset' element to which the `click' event
would bubble up.
PointedEars
Dec 20 '05 #4

"RobG" <rg***@iinet.net.au> wrote in message
news:43***********************@per-qv1-newsreader-01.iinet.net.au...
Stuart wrote:
I have a page where I utilise the left and right cursor keys to change an
What are 'left and right cursor keys'? Do you mean mouse buttons? Not
everyone has left and right mouse buttons. Not everyone navigates with a
mouse, or even has a mouse.

Can users change images if scripting is disabled or not available?


No I mean the arrow keys on the key board, not sure what the correct name is
for these

I am the only user of this page so compatablity issues don't come into it

How do I take focus away from the radio buttons after they have been
clicked
Presumably some other element has focus when you detect the 'cursor keys'.
Set that element to have focus whenever a radio button is clicked by
putting an onclick event on each radio button:

<input type="radio"
onclick="if(someOtherElement.focus)someOtherElemen t.focus()"
... >


What actually has focus when a page is first loaded.?

Take a look at the page in question
http://www.stuartstuart.fsnet.co.uk/weather/handler.htm

The left and right arrows move the maps back and forward. however when a
radio button is clicked the arrow keys scrooll through the buttons until I
click somewhere else,

If I attach an event to the onClick of the radio button, what should I
attach focus to?

The UI sounds confusing and overly complicated.


What exactly is "UI" I am not a developer or a javaScripter, just simply
trying to get a page to work in the way I would like it to work!
Dec 20 '05 #5
Stuart wrote:
"RobG" <rg***@iinet.net.au> wrote in message
news:43***********************@per-qv1-newsreader-01.iinet.net.au...
Stuart wrote:
I have a page where I utilise the left and right cursor keys to change an
What are 'left and right cursor keys'? Do you mean mouse buttons? Not
everyone has left and right mouse buttons. Not everyone navigates with a
mouse, or even has a mouse.

Can users change images if scripting is disabled or not available?

No I mean the arrow keys on the key board, not sure what the correct name is
for these


Arrow keys will do me. In the good ol' days, they were used to move
the cursor on the screen hence 'cursor keys' I guess, but now I think
'arrow keys' will be more widely understood.


I am the only user of this page so compatablity issues don't come into it
Stuff posted here is assumed to be for the general web unless stated
otherwise.

How do I take focus away from the radio buttons after they have been
clicked
Presumably some other element has focus when you detect the 'cursor keys'.
Set that element to have focus whenever a radio button is clicked by
putting an onclick event on each radio button:

<input type="radio"
onclick="if(someOtherElement.focus)someOtherElemen t.focus()"
... >


What actually has focus when a page is first loaded.?


That likely depends on the browser and how you arrived at the page.


Take a look at the page in question
http://www.stuartstuart.fsnet.co.uk/weather/handler.htm
The page doesn't work at all. You have used a reserved word for your
very first variable name:

var int=24
All statements should be terminated by a semi-colon even though they
will be inserted automatically - don't leave it to chance.


The left and right arrows move the maps back and forward. however when a
radio button is clicked the arrow keys scrooll through the buttons until I
click somewhere else,
Using which browser? It works for me OK in IE 5.2 (Mac OS) but not
any other browser I tried.

If I attach an event to the onClick of the radio button, what should I
attach focus to?
Probably the document body since that is where the onkeydown is
defined, try:

function docFocus(){
var docBody = document.body || document.documentElement;
if (docBody && docBody.focus) docBody.focus();
}
But it 'works' for me in IE 5.2, so the point seems moot.

The UI sounds confusing and overly complicated.

What exactly is "UI"


User interface.

--
Rob
Dec 20 '05 #6
Stuart wrote:
"RobG" <rg***@iinet.net.au> wrote [...]:
Stuart wrote:
I have a page where I utilise the left and right cursor keys to change
an


What are 'left and right cursor keys'? Do you mean mouse buttons? Not
everyone has left and right mouse buttons. Not everyone navigates with a
mouse, or even has a mouse.

Can users change images if scripting is disabled or not available?


No I mean the arrow keys on the key board, not sure what the correct name
is for these

I am the only user of this page so compatablity issues don't come into it


Well, you crippling your own keyboard navigation deliberately certainly
strikes me as being an issue ...
The UI sounds confusing and overly complicated.


What exactly is "UI" [...]


<http://foldoc.org/?query=UI&action=Search>
PointedEars
Dec 20 '05 #7

"RobG" <rg***@iinet.net.auau> wrote in message
Arrow keys will do me. In the good ol' days, they were used to move the
cursor on the screen hence 'cursor keys' I guess, but now I think 'arrow
keys' will be more widely understood.

i'm showing my age :-(

Take a look at the page in question
http://www.stuartstuart.fsnet.co.uk/weather/handler.htm


The page doesn't work at all. You have used a reserved word for your very
first variable name:

var int=24


It has worked fine for me over the past few years, im on IE 5

however I have amended it to to intT

Where can i find a list of reserved words?

The left and right arrows move the maps back and forward. however when a
radio button is clicked the arrow keys scrooll through the buttons until
I click somewhere else,
Using which browser? It works for me OK in IE 5.2 (Mac OS) but not


function docFocus(){
var docBody = document.body || document.documentElement;
if (docBody && docBody.focus) docBody.focus();
}

Fitted this in and its all working how I want it to, many thanks....
Definatly being lazy now, How do I assign the up and down arrow keys to
scroll through the "grp" radio buttons.
Dec 20 '05 #8

"Thomas 'PointedEars' Lahn"


Well, you crippling your own keyboard navigation deliberately certainly
strikes me as being an issue ...


What navigation is there to do on that page other than scroll through the
images? Personally I can,t think of a better way of viewing these images
than to use the cursor keys!

Dec 20 '05 #9
Stuart wrote:
"Thomas 'PointedEars' Lahn"
Well, you crippling your own keyboard navigation deliberately certainly
strikes me as being an issue ...


What navigation is there to do on that page other than scroll through the
images? Personally I can,t think of a better way of viewing these images
than to use the cursor keys!


Read again. With blur() you are _preventing_ yourself from using the
cursor keys again (or require yourself to tab back). You are looking
for focus()ing another control onclick or for another UI approach.
PointedEars
Dec 20 '05 #10

"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:54****************@PointedEars.de...
Stuart wrote:
"Thomas 'PointedEars' Lahn"
Well, you crippling your own keyboard navigation deliberately certainly
strikes me as being an issue ...


What navigation is there to do on that page other than scroll through the
images? Personally I can,t think of a better way of viewing these images
than to use the cursor keys!


Read again. With blur() you are _preventing_ yourself from using the
cursor keys again (or require yourself to tab back). You are looking
for focus()ing another control onclick or for another UI approach.
PointedEars


I have never suggested blurring anything
Dec 20 '05 #11
Stuart wrote:
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote [...]
Stuart wrote:
"Thomas 'PointedEars' Lahn"
Well, you crippling your own keyboard navigation deliberately certainly
strikes me as being an issue ...
What navigation is there to do on that page other than scroll through
the images? Personally I can,t think of a better way of viewing these
images than to use the cursor keys!

Read again. With blur() you are _preventing_ yourself from using the
cursor keys again (or require yourself to tab back). You are looking
for focus()ing another control onclick or for another UI approach.
[...]


I have never suggested blurring anything


True, however

,-[news:11*********************@g44g2000cwa.googlegro ups.com]
| You can use the blur method.

,-[news:43***********************@per-qv1-newsreader-01.iinet.net.au]
| > How do I take focus away from the radio buttons after they have been
| > clicked ?
| Not everyone navigates with a mouse, or even has a mouse.

But, with the "page in question" you provided, the logical design
choice is indeed either to use the blur() method of the radio button
on click. I quick-tested that with

javascript:alert(document.getElementsByName("int")[0].onclick=function()
{ this.blur(); })
and
javascript:alert(document.getElementsByName("int")[1].onclick=function()
{ this.blur(); })

However, this way users (you) will have to tab-navigate back to the
radio button and can only do one change with the up/down keys.

So you might want to consider the alternative of providing Left/Right
buttons for navigation that gain focus after a selection, applying the
focus() method on the respective element object. The cursor keys can
still be used to trigger either button, so no functionality would be
lost or duplicated.

But please, stop abusing tables and start using forms properly; there
is the `fieldset' element which you can also use for handling the
bubbling `click' event. Valid markup would be an advantage, too.

<URL:http://validator.w3.org/>

And, last but not least, you might want to consider using an existing
sender address as you will receive no more help from me otherwise, not
considering that you are already running the risk of losing your account
anyway.

<URL:http://www.interhack.net/pubs/munging-harmful/>
<URL:http://www.cw.com/legal/acceptable_use_policy.html>
HTH

PointedEars
Dec 21 '05 #12
Thomas 'PointedEars' Lahn said the following on 12/20/2005 7:24 PM:
Stuart wrote:
<snip>
And, last but not least, you might want to consider using an existing
sender address as you will receive no more help from me otherwise, not
considering that you are already running the risk of losing your account
anyway.


Someday, you might actually wake up to Reality and realize that your
empty threats at losing an account are as worthless as trying to pole
vault over the moon.

<snipped useless URL's>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '05 #13

"Stuart" <ff**@hhhde.khr> wrote in message
Fitted this in and its all working how I want it to, many thanks....
Definatly being lazy now, How do I assign the up and down arrow keys to
scroll through the "grp" radio buttons.


messed about, and got it to work in a fashion.

Have I went about disabling the scroll down with the down key in the correct
way! I got confused with this, its working (IE5) but not too sure how!

the image changes all work on the cursor keys!
remember this is only intended for my use, so I havnt tried for browser
compatability!

Dec 22 '05 #14

"Thomas 'PointedEars' Lahn" <Po*********@web.de>

And, last but not least, you might want to consider using an existing
sender address as you will receive no more help from me otherwise
But you have not provided any help !!!!!

take a look at the posts by robG & web.dev, that is help, your post in
contrast are irritating pedantic drivel!

, not
considering that you are already running the risk of losing your account
anyway.


yawn
Dec 22 '05 #15
Stuart wrote:
"Thomas 'PointedEars' Lahn" <Po*********@web.de>
And, last but not least, you might want to consider using an existing
sender address as you will receive no more help from me otherwise


But you have not provided any help !!!!!


If you just learned to read and understand ...
PointedEars
--
"And all those exclamation marks, you notice? Five? A sure sign of
someone who wears his underpants on his head."
-- Terry Pratchett in "Maskerade"
Dec 22 '05 #16
Thomas 'PointedEars' Lahn said the following on 12/22/2005 8:52 AM:
Stuart wrote:

"Thomas 'PointedEars' Lahn" <Po*********@web.de>
And, last but not least, you might want to consider using an existing
sender address as you will receive no more help from me otherwise


But you have not provided any help !!!!!

If you just learned to read and understand ...


And if we could only get YOU to read and understand.....

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 22 '05 #17

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

Similar topics

1
by: Matt | last post by:
The following code is try to validate if the user selects a radio button choice. I dont understand why document.UserInputs.question.value; gets undefined value even user make a choice. I tried...
3
by: Terry Murray | last post by:
Hi All: I would like to know how to set the focus on a radio button (if it is possible) I tried button.focus() but with no luck The reason that I need to do this is to validate a form. If...
1
by: Michael Albanese | last post by:
I am developing an application to handle my compay's OSHA reporting requirements. Some of the input criteria are technical and narowly defined, so I was trying to prvide what i call "Context...
2
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button...
1
by: s.chelliah | last post by:
Hi, I am trying to use javascript, div tag and radio button to disable/enable a text box. It works fine in netscape and firefox, but in IE, the text box is not disabled when the user checks the...
0
by: ballamber | last post by:
This is a solution to the problem. Works with .NET 2.0. So the problem is displaying a data bound read-only checkbox or radio button in a GridView without actually disabling those controls. I...
1
by: FunkHouse9 | last post by:
I'm trying to develop an order page and in one section, the customer specifies a shipment type using radio buttons that is submitted to the shopping cart. There are 4 buttons. If either of the...
3
by: jahphill | last post by:
Hey. I thought id make a seperate discusion because the other became a bit lengthy and confusing. Aim: Create a php file which works with the script below, which makes the radiobuttons work =D...
1
by: sososm | last post by:
Hy experts I need a little help here. Can anybody tell me how to select a radio button from another program knowing the name,id or text of the radio button. I want to automate internet explorer...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.