Page 1 of 1

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

Posted: Wed Aug 17, 2011 6:25 am
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.

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

Posted: Wed Aug 17, 2011 6:58 pm
by Christopher
Use the HTML <label> tag.

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

Posted: Thu Aug 18, 2011 2:50 am
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!

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

Posted: Thu Aug 18, 2011 4:46 am
by simonmlewis
Why in Internet Explorer does it work only on Text and not on Images?
On Firefox it works on both.

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

Posted: Thu Aug 18, 2011 12:52 pm
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.

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

Posted: Thu Aug 18, 2011 12:56 pm
by simonmlewis
So the suggestion cannot be done on the browser used by about 60% of the world?

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

Posted: Thu Aug 18, 2011 1:21 pm
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