Page 1 of 2 12 LastLast
Results 1 to 15 of 29

Thread: radio buttons to images

  1. #1
    Join Date
    Jun 2011

    radio buttons to images

    I am trying to turn radio buttons to show images based off the label of the radio button input instead of using radio buttons.

    I have to use only javascript for this and I am at a loss. Can anyone help me out.

  2. #2
    Join Date
    Dec 2002
    St. Louis, MO, USA
    Your question is confusing. Please clarify.
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long


  3. #3
    Join Date
    Jun 2011
    I use some store software that has radio buttons for color choices. I am trying to figure out how to change the radio button selection from radio style buttons to a small image of the color. I know it has to be with javascript but I am at a loss how to do it.

    So in the code it has the <input> and a <label> I would like it to load an imaged based off the <label> tag.


    <label>white</label> instead of radio button it would load a 50x50px image of white

    I hope that clears it up some.

  4. #4
    Join Date
    Sep 2008
    Akron, OH
    yea, you'd use javascript to read whatever the label is and display the image accordingly.

    What's the code look like so far?
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  5. #5
    Join Date
    Jun 2011
    Thats the kicker Im at a loss. I don't know where to start with this. I understand a bit of javascript and I have been looking all over the web for help on this and I haven't found much.

    I dont usually code in Javascript but I have to with the company that we are using for the cms solution

  6. #6
    Join Date
    Jun 2011
    Also great wedding site.. the picture of you two under the pink flowers is a great shot.

  7. #7
    Join Date
    Jun 2011
    I have some code that should help switch out the color name with an image. But I don't think it will work the way I need it. Here it is:

    replaceImages = new Array(

    function firdom(){
    if(document.getElementsByTagName && document.createElement){
    for (l=1;l<=6;l++){
    function scanandreplace(h1s,tag){
    // or newimg.src=chunks[1];

  8. #8
    Join Date
    Jun 2011
    Where the words white is I woudl like to pull from the <label> tag this way It could be used without having to edit it each time. Then I would like the image to become a radio button input.

  9. #9
    Join Date
    Sep 2008
    Akron, OH
    Thanks for the compliment on the site

    Anyway, I'm having a hard time understanding exactly what you're trying to achieve. Could you possibly create a visual representation? Maybe illustrate what it looks like now, and what you are trying to get it to look like?

    What does your HTML look like that you're trying to transform? You said it has labels and inputs, but is it wrapped in a DIV or anything? Are there any classes or ID's involved?
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  10. #10
    Join Date
    Jun 2011
    Here are links to help explain I hope.

    Image 1 - Currently

    Image 2 - Goal

  11. #11
    Join Date
    Sep 2008
    Akron, OH
    Ah yes, now we're cooking! Do you want to keep the actual radio button there? How is the user suppose to know which color is selected?
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  12. #12
    Join Date
    Jun 2011
    The user would just click on the color and the software will load the right photo in the large photo area.. That part works now. Its just the radio button part that doesnt work.

  13. #13
    Join Date
    Sep 2008
    Akron, OH
    This should help explain how it's accomplished. Basically, you need to use JavaScript to figure out what radio buttons are present. You're then building a new list of colors and putting it right after the radio buttons. You then need to bind an onclick action to the newly added list which will select the correct radio button when it's clicked.

    Check it out here:

    If everything is working, you'd then hide the radio buttons with CSS, leaving you with the desired result.

    Good luck, and let me know if you need any clarification!
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  14. #14
    Join Date
    Dec 2005


    Alternative solution ... slightly smaller.
    <title> Radio Button Colors </title>
    <script type="text/javascript">
    // For: http://www.webdeveloper.com/forum/showthread.php?t=247592
    function setRBtn(RBtnGroup,which) {
      var sel = document.getElementsByName(RBtnGroup);
      for (var i=0; i<sel.length; i++) {
        if (i == which) {
          sel[i].checked = true;
    // Following is not needed, only for demo
    function toggleDisplay(IDS, flag) {
      var tmp = document.getElementById(IDS);
      if (flag == true) { tmp.style.display = 'inline'; }
                   else { tmp.style.display = 'none'; } 
    <style type="text/css">
    #color_Options li {
     width: 50px; height: 50px;
     border: solid 1px #000;
     float:left;margin:5px 5px;
    .blue {background-color: blue;}
    .green {background-color: green;}
    .sherbert {background-color: orange;}
    .yellow {background-color: yellow;}
    .red {background-color: red;}
    .black {background-color: black;}
    .white { background-color: white;}
    // Following is not needed, only for demo
    <input type="checkbox" onchange="toggleDisplay('RBtnBlock',this.checked)">
    <div id="RBtnBlock" style="display:none"> 
    <!-- change to 'block' for testing and 'none' after testing -->
     <input type="radio" name="RBtn" value="white"> White
     <input type="radio" name="RBtn" value="blue"> Blue
     <input type="radio" name="RBtn" value="green"> Green
     <input type="radio" name="RBtn" value="orange"> Orange
     <input type="radio" name="RBtn" value="yellow"> Yellow
     <input type="radio" name="RBtn" value="red"> Red
     <input type="radio" name="RBtn" value="black"> Black
    <ul id="color_Options">
     <li class="white" onclick="setRBtn('RBtn',0)"></li>
     <li class="blue" onclick="setRBtn('RBtn',1)"></li>
     <li class="green" onclick="setRBtn('RBtn',2)"></li>
     <li class="sherbert" onclick="setRBtn('RBtn',3)"></li>
     <li class="yellow" onclick="setRBtn('RBtn',4)"></li>
     <li class="red" onclick="setRBtn('RBtn',5)"></li>
     <li class="black" onclick="setRBtn('RBtn',6)"></li>
    <!-- following is for testing purposes only -->
    <div style="float:left">
    <span style="float:left">Chosen: </span><div id="colorChosen"
     style="width:50px; height:50px; border:solid 1px black; float:left;
     margin:5px 5px; background-color:white; display:block;">
    <br style="clear:both">

  15. #15
    Join Date
    Jun 2011
    Im going to give it a try and ill let you know how it works out. Thanks a ton.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.13394 seconds
  • Memory Usage 3,010KB
  • Queries Executed 15 (?)
More Information
Template Usage (36):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (75):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates