Search code examples
javascriptjqueryradio-buttonslider

Link a set of radio buttons to a div


first of all: I'm a newbie when it comes to JS/jQuery - so please be gentle^^

Here my Question:

I have a set of customized(styled) radio buttons (currently 10) and 2 divs with a left/right arrow background-image. Both divs set the "left" value of a so called "Slider" per function to move the div to left and right. So - I want to have the functionality that when I click the left/right arrow that a radio button will move it's active state to the next radio button. Is this possible? Thanks in advance!


Solution

  • I think you want to do something like this - http://jsfiddle.net/7xe9g/

    $("#left").click(function () {
      cur--;
      if (cur < 1) { cur = 6;}
      $("#r" + cur).prop("checked", true)
    });
    

    The code could use a little cleaning up (merging the two functions, etc)… but it gets the point across of how you can change the selected radio button left and right.