I'm currently available for freelance projects. Enquire within.

fancyradios

I recently read a fantastic tutorial by Aaron weyenberg which shows how to make checkboxes more visually appealing. This got me thinking, if checkboxes, why not radio buttons too? based on Aarons idea I have been able to create the same visually appealing technique, using radio buttons. I decided to take this one step further and apply it to a table. This is a proof of concept to show you how  it works!

download

demo11

The Idea

I wanted to create 2 mandatory option sets that a user could choose.  To make this more visually appealing I want to hide off the radio button inputs and use an anchor links to make it a bit more usable.

The HTML

To marry up each option with the fields around it a class has been set to every column that is selectable. This enables elements to be grouped together and makes actions such as highlighting much simpler in javascript.

The jQuery

When a user clicks on a select button it initiates a click function in jQuery. The first action is to remove the highlighting on the old row. Then we find the radio button of the new selection and add a checked state to it. Finally we add a new style class on to the column which gives the visual impact that a selection has been made

Application

Radio buttons are an extremely useful tool in web form design, however they are one of the least compromising in terms of styling. I hope this demonstration may show a way to bypass this issue and ultimately give a better user experience when interacting with forms in future.

As ever I am always keen to hear your feedback. Please let me know what you think, or if you have suggestions for ways of improving this code. Please feel free to download the demo and try it out for yourself!


About the author

My name is Philip Beel. I have four years commercial experience in front end web development. My disciplines include XHTML, CSS, PHP, MYSQL, Smarty and javascript. I am also a keen advocate of the jQuery framework.

Read more posts by


63 Comments on Fancy Radio Buttons With jQuery

  1. Aaron Weyenberg

    Well done! I was going to write up a radio button version, but you saved me the work :)

    « Reply


  2. Louis Gubitosi

    thanks for the tutorial… will be using this in the near future!

    « Reply


  3. Jamie

    Beautiful Solution! This is so in my toolbox. Brilliant!

    « Reply


  4. Astho

    Cool man…, thanks..

    « Reply


  5. Yasir Haleem

    cool man you solution looks great and works but i have some points i would’t like to use this because of markup (a lot of markup) when we can achieve same with 3,4 of jquery code and 10,20 line of markup :)

    « Reply

    philipbeel Reply:

    @Yasir Haleem, Thanks for your message. I can understand your concern, if you can see a way to refactor the code to achieve the same ends in fewer lines I would be happy to consider this.

    « Reply

    West Hartford Massage Spot Reply:

    @Yasir Haleem, Yasir, do you currently have anything like that? I’m looking for radio button gif images that will have onmouseover & onclick styles Like this: http://www.westhartfordmassagespot.com/book-a-massage-2/

    Thanks for any help.

    Brian

    « Reply

    West Hartford Massage Spot Reply:

    @Yasir Haleem, to clarify, the buttons I’m referring to, click thru until you get to the Date & Time selection page of the BookFresh scheduling form: http://www.westhartfordmassagespot.com/book-a-massage-2/

    « Reply


  6. 内衣

    wa!cool! I love it!

    « Reply


  7. normalfx

    Thanks for sharing. It would be in my work so soon.

    « Reply


  8. Russ

    Very cool indeed – I will use this for sure

    « Reply


  9. Gavin

    How easy would it be to convert this to a table made from div’s? Specifically to be able to have the options move in a carousel (or is this possible to do with a table?)

    Thanks,
    Gavin

    « Reply

    philip beel Reply:

    @Gavin, Hi, do you have a test page where you are trying to apply this. I could probably help you out if I could better visualise it.

    « Reply

    Gavin Reply:

    @philip beel,

    Hi Philip, thanks for the quick reply! I have a work in progress site I’ve been working on for a while, and a part of it is to have options to buy/subscribe to a video. Anyway I thought this would be a nice way of doing it as there will be different options to buy with varying bandwidth and time limits which could be 1 or could be 10, so I’d like to have the ability to display maybe 4 options and have a carousel typ arrow to show further options. Hopefully that gives you an idea :)

    Also, I’m still a bit of a beginner with css and jquery but am usually able to change stuff that’s almost what I need but just needs some tweaking…

    http://www.hoststreamsell.com/elgg-1.8/pg/secure_videos/view/142

    « Reply

    Gavin Reply:

    @Gavin,
    Forgot to mention, press the Buy/Subscribe tab :)

    philip beel Reply:

    @Gavin, Ok I took a look at this and it should be possible to modify with some custom code, maybe check out my advanced anything slider for ideas on tying this into a carousel
    http://theodin.co.uk/blog/development/advanced-jquery-slider.html

    Gavin Reply:

    @philip beel, Thanks, I’ll check out the slider. Any good starting points for me to look at for converting the table to div, or do I not need to do that with the slider?

    Thanks again!

    « Reply

    philip beel Reply:

    @Gavin, I would try focusing on where the jQuery defines the value, each table block should show you this, looking at the API will probably help:

    http://api.jquery.com/

    Gavin Reply:

    @Gavin, Ok will do. Thanks!


  10. Silence

    Hi! Your initiative is great. I just wonder if we can use the “label” tag with “for” attribute instead of creating a link to do the same. This will save some lines of code and it will be a little more standard I think. I’m just worry about IE behaviors about this.

    Thanks for sharing your code.

    Regards.

    « Reply

    philip beel Reply:

    @Silence, Not sure if that would produce semanic markup. Planning to write a follow up post:

    http://dev.theodin.co.uk/fancyForm/fancyForm0.2/

    « Reply


  11. Chris

    Can you give a hint on how to change the background color of the selected tab? I’m having trouble finding it in the css.

    Otherwise this script is working very very well.

    « Reply


  12. Ameen

    Hi,
    Cool….
    I have a question. I wanna use the same method but more simpler. I have a table with 3 rows and 3 columns. each row should have its own radio buttons. for example:
    Cat Door Bird
    rainingPicture CatPicture bagPicture
    usbDefinition chairDefinition CatDefinition
    so basically it’s like a recognition test. so the user should pic the cat word and the cat picture and the cat definition. I don’t want to use the standard radio button. I want to highlight it by a color like this demo. Also to be able to read the answer by my php code to check the word/picture/definition in the database.
    Any thoughts?

    « Reply


  13. Stefan

    hi, this is so nice! i tried to get it on my own but i failed. i want to do this without tables but with divs… so what do i have to change in the code? thx so much!

    « Reply


  14. Clint Farish

    Thanks for another excellent post. Where else could anybody get that kind of information in such an ideal way of writing? I’ve a presentation next week, and I am on the look for such information.

    « Reply


  15. iphone docking station

    I Just bookmarked this post and I will probablybe checking back soon. Excellent

    « Reply


Leave a comment


Had a lovely evening at crazy bear with @keepjacqui another year older!

Follow me