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.



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 (permalink)  
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.
Reply With Quote

  #2 (permalink)  
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
Send a message via Skype™ to ukgeoff
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?
Reply With Quote
  #3 (permalink)  
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.
Reply With Quote
  #4 (permalink)  
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.
Reply With Quote
  #5 (permalink)  
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
Send a message via Skype™ to ukgeoff
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?
Reply With Quote
  #6 (permalink)  
Old Dec 29th, 2006, 17:39
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,604
Thanks: 0
Thanked 6 Times in 6 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
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.
__________________
I've got <style> and .class
Reply With Quote
  #7 (permalink)  
Old Dec 29th, 2006, 20:24
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,951
Blog Entries: 7
Thanks: 7
Thanked 3 Times in 3 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
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.
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
  #8 (permalink)  
Old Jan 1st, 2007, 01:12
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
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.
Reply With Quote
  #9 (permalink)  
Old Jan 1st, 2007, 01:18
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
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...
Reply With Quote
  #10 (permalink)  
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.
Reply With Quote
  #11 (permalink)  
Old Jan 4th, 2007, 01:53
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
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...
Reply With Quote
  #12 (permalink)  
Old Jan 4th, 2007, 03:08
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
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/
Reply With Quote
  2 links from elsewhere to this Post. Click to view. #13 (permalink)  
Old Jan 4th, 2007, 12:28
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
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)
Reply With Quote
  #14 (permalink)  
Old Jan 4th, 2007, 20:38
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
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.
Reply With Quote
  #15 (permalink)  
Old Jan 5th, 2007, 00:13
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
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.
Reply With Quote
  #16 (permalink)  
Old Jan 5th, 2007, 01:50
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
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/
Reply With Quote
  #17 (permalink)  
Old Jan 5th, 2007, 10:42
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
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)
Reply With Quote
  #18 (permalink)  
Old Jan 5th, 2007, 12:43
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
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...
Reply With Quote
  #19 (permalink)  
Old Jan 5th, 2007, 13:41
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Any way to use an image for a radio button?

Easy matey, I was joking! LOL
It's not bad at all, in fact, it's very organized and nice to read....
I just prefer the 'hard coding' everything so I can crunch my scripts.
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #20 (permalink)  
Old Jan 5th, 2007, 22:25
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Any way to use an image for a radio button?

Haha, you got me all riled up and I spent some time looking around on Google afterwords, seeing if there was something about it that was bad

I know what you mean about the hard coding. When I first started learning JavaScript, I saw a script that was coded the way I do it now and it seemed to make more sense. I have run into a couple of problems with the style, though. Some functions (specifically Ajax ones) can't be sent back and forth between different functions inside a variable. As far as I know anyway. I'm just super anal about making code look as pretty as I can, so I'll stick with it.
Reply With Quote
Reply

Tags
button, graphic, radio

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.webforumz.com/web-page-design/11232-any-way-to-use-an-image.htm
Posted By For Type Date
karinne's bookmarks tagged with "CSSForms" on del.icio.us Post #13 Refback Feb 19th, 2008 16:35
Checkbox input problem - HTMLforums – Free Webmaster HTML Help and Discussions Post #13 Refback Jan 19th, 2007 10:48
karinne's bookmarks on del.icio.us This thread Refback Jan 11th, 2007 21:16

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Radio Button Response! :( jahphill PHP Forum 33 Oct 25th, 2007 22:15
Radio Button Problems in ActionScript 3.0 dgstarr Flash & Multimedia Forum 1 Sep 6th, 2007 17:11
automatic pop-up when click on a radio button joshcxa JavaScript Forum 2 Aug 1st, 2006 06:06
Help Please - Radio Button Labels not showing sandyb Flash & Multimedia Forum 0 Jan 16th, 2006 22:56
Delete All Row (Select All Row Using Radio Button) Monie Classic ASP 37 Nov 5th, 2004 09:21


All times are GMT. The time now is 22:44.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43