Any way to use an image for a radio button?

This is a discussion on "Any way to use an image for a radio button?" within the Web Page Design section. This forum, and the thread "Any way to use an image for a radio button? are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack (3) Thread Tools
  1 links from elsewhere to this Post. Click to view. #1  
Old Dec 27th, 2006, 17:44
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Any way to use an image for a radio button?

Does anyone know a way to use an image as a radio button? I've tried a background image in css and several experiments, but nothing works so far.

It's very maddening, LOL. Right clicking the button and choosing "view background image" shows the image I want, but it won't appear on the page.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 27th, 2006, 22:03
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

I've never seen this done to my knowledge.

What exactly are you trying to achieve?

Could there be another way?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 27th, 2006, 22:40
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

Well, I don't have Flash, which is the only obvious way to style a radio button that I can think of. Or perhaps use a javascript sniffer and use a rollover/onclick for js enabled browsers, but that seems a bit heavy for a style that some people can't see.

What I want to achieve is a better-looking, easier-to-click radio button. Running the dimensions up looks awful.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 28th, 2006, 16:01
Junior Member
Join Date: Dec 2006
Location: ...
Age: 14
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

Ouch, big programme there, and it won't work with CSS it might work with javascript but otherwise...

Edit by Geoff:
What is the point of this post? In order to maintain the integrity of the forums, please do make post that add nothing to the thread discussion.

Last edited by ukgeoff; Dec 29th, 2006 at 16:34.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Dec 29th, 2006, 16:36
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

Thing is Mason, thinking from the end-user/accessibility viewpoint, how will people know they should treat these 'images' as radio style buttons?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Dec 29th, 2006, 17:39
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Any way to use an image for a radio button?

instead of replacing the radio buttons with an image have you considered using CSS to style them to match your site more? Seems that would be a comfortable middle ground.
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Dec 29th, 2006, 20:24
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,184
Blog Entries: 7
Thanks: 27
Thanked 22 Times in 19 Posts
Re: Any way to use an image for a radio button?

This is entirely possible, indeed!

I have seen this done on a friends CMS... he is in fact an admin here - spinal007.

I'll see if I can draw his attention to this thead.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jan 1st, 2007, 01:12
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

I've made custom radio boxes before. Let me see if I can explain this clearly:

I started out with three instances of a radio button - off, active and selected. For the HTML, I made a <div> with a CSS background image of the radio button and a hidden radio button element inside. Using JavaScript, I wrote a quick little function that switched the background and told the radio button to be selected when the user clicked on the <div>.

Understand? The only problem is that is uses JavaScript. It wouldn't be too difficult to make it still work without the extra styling if JS was disabled, though.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jan 1st, 2007, 01:18
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

I should write an article about this...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Jan 3rd, 2007, 22:02
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

That's a good workaround Ryan, thanks. If you're going to need js though, why not just use a rollover/onclick? I'll try to use the concept with css but I'm not optimistic about IE support for it.

I may investigate XForms even though they require a browser plugin. I'm not through with introductory XSLT yet but XForms is on my list.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Jan 4th, 2007, 01:53
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

I made custom checkboxes once and it worked fine in IE. I don't quite understand what mean about the rollover/onclick stuff...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Jan 4th, 2007, 03:08
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

I couldn't find my old script, so I made a new one. I found the old checkbox images, though. This is fairly universal, but you'll need to be a little familar with JavaScript to play around with it. I haven't tested in IE, but it works fine in Firefox and Safari. I don't really see any reason why it wouldn't work in IE. Let me know if there are any problems with it.

Oh, and if someone has JavaScript disabled, there is no background image and a regular checkbox is displayed.

http://ryanfait.com/checkbox/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  2 links from elsewhere to this Post. Click to view. #13  
Old Jan 4th, 2007, 12:28
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: Any way to use an image for a radio button?

I set up a quick example: http://www.pinesandneedles.com/radio
The idea is similar to ryan's above...

The concept:
1. Find all forms on page
2. Find all input controls with the form
3. Loop through controls and find the ones with type='checkbox' or type='radio'...
3.1. Hide control, append an image next to the control
3.2. Attach events to image (click, mouseover, etc)

You can develop it further by using different images, ie.: some of my checkboxes have a class 'YesNo', which displays a green tick when the control is checked and a red x when the control is not checked... etc

PS.: Ryan, play around with the bottom checkboxes and you'll see the image/checkbox don't always match...

PPS.: Works without JS too!
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Jan 4th, 2007, 20:38
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

Okay, I'll have to do a little more playing with it. It can't be fooled in Safari. In Firefox, if you click the real checkbox, it doesn't fire the other one, but that doesn't matter because they'd normally be hidden. I've have a gander at it in Windows.

On yours, I just get 5 alerts saying "Cannot insert HTML" in Safari... No radio buttons or checkboxes are visible.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Jan 5th, 2007, 00:13
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

Aw, my script runs horribly in IE6. I'm working on fixing it now and adding support for custom radio buttons. I think I will write a small article on it and provide the code once I get it working properly.

Oh, and I should note. Those looking at mine in IE will see a background color around the images. It's just because I'm using PNG24 and IE doens't support that. I'll change those to GIFs later today.

Last edited by Ryan Fait; Jan 5th, 2007 at 00:16.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Jan 5th, 2007, 01:50
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

Update:

I added radio buttons to the page. It has now been fixed and tested in IE 5, 6, 7; Opera; Firefox; and Safari. This was a fun little project

http://ryanfait.com/checkbox/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Jan 5th, 2007, 10:42
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: Any way to use an image for a radio button?

"handle: function() {"
Bad coding style Ryan! Very bad! LOL
I'm only saying that because I like to crunch my scripts when I'm done with them, and your style isn't crunching friendly - but it does look cool.

Damn Safari. I've just downloaded a Windows equivalent called swift and I'll have those problems sorted eventually....
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Jan 5th, 2007, 12:43
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

It's not bad coding! It's an organized approach to multiple functions that should be grouped accordingly. Find me a shred of evidence about why my way is bad, other than personal preference, and I'll willingly change my habbits...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #19  
Old Jan 5th, 2007, 13:41
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts