Search code examples
javascriptjqueryradio-buttonhref

dynamic href using radio buttons


Is there a way to create a dynamic href using radio buttons?

radio = value1
radio = value2
radio = value3

<a href="test.php?value=radio">

Solution

  • I wonder what are you trying to do, however you can:

    $(function(){
      $('input[type="radio"]').click(function(){
        if ($(this).is(':checked'))
        {
           $('a').attr('href', 'test.php?value' + $(this).val()).text($(this).val()).appendTo($('body'));
        }
      });
    });