How do you 'select' radio when click text next to it?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do you 'select' radio when click text next to it?

Post by simonmlewis »

Code: Select all

<table width='100%' class='table' cellspacing='0' cellpadding='0'>
<tr bgcolor='#ffffff' onMouseOver="this.bgColor='#E7E7E7';" onMouseOut="this.bgColor='#FFFFFF';"><td width='20px'><img src='images/icon_orange.png'  class='colorboxes'/></td><td><input type='radio' name=itemcode value='2342342'>Orange</td></tr></table>
I want to be able to click "Orange" or the IMG and it selects the radio button.

Seen this done so many times, but cannot find how it's achieved.

Any help or answers would be great.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do you 'select' radio when click text next to it?

Post by Christopher »

Use the HTML <label> tag.
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you 'select' radio when click text next to it?

Post by simonmlewis »

Heavens that's easy.
And I read that many people aren't aware of that simple function.
I did find a Javascript way of doing it, but what's the point of that when Label is available.

Brilliant!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you 'select' radio when click text next to it?

Post by simonmlewis »

Why in Internet Explorer does it work only on Text and not on Images?
On Firefox it works on both.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How do you 'select' radio when click text next to it?

Post by califdon »

simonmlewis wrote:Why in Internet Explorer does it work only on Text and not on Images?
On Firefox it works on both.
Because browser development teams implement the standards to varying degrees. It's a curse.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you 'select' radio when click text next to it?

Post by simonmlewis »

So the suggestion cannot be done on the browser used by about 60% of the world?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How do you 'select' radio when click text next to it?

Post by califdon »

I never tried to use that particular feature, so I don't know, but in general, yes, MANY details within HTML/CSS specs are not uniformly implemented among IE, Mozilla, Chrome, Safari, Opera. That's why web developers install all of them and test pages for operation in all. Usually IE is far behind the others in implementing standards that don't originate in Redmond; they often have a "better" way to do things--the Microsoft way. So the poor web developers have to include code to detect what browser is being used and branch their code depending on which it is. Or just not use some perfectly good syntax because it won't work in IE. It's very common. Check out a few of these:
http://webdesign.about.com/od/internete ... 082906.htm
http://en.wikipedia.org/wiki/Internet_E ... _model_bug
http://forums.htmlcenter.com/programmin ... lorer.html
http://www.impressivewebs.com/7-javascr ... irefox-ie/
http://geekswithblogs.net/mnf/archive/2 ... cript.aspx
Post Reply