How to make a button that will copy the value of the multiple radio buttons selected?

can someone help me?

here is my current code,

$("#button1").on("click", function() {

  var radio1 = $("input[name='option1']:checked").val();
  var radio2 = $("input[name='option2']:checked").val();
  var radio3 = $("input[name='option3']:checked").val();
  var radio4 = $("input[name='option4']:checked").val();
  var qstring = "1. " + radio1 + "<br /> " + "2. " + radio2 + "<br />" + "3. " + radio3 + "<br />" + "4. " + radio4;
  var result2 = qstring.fontsize(3);
  document.getElementById("Center").innerHTML = result2;
  result2.select();
  document.execCommand("Copy");
});

I know now the answer, you just have to call the div id which the result is being display. thanks.

$("#button1").on("click", function() {
    var target = document.getElementById("Center");
    var range, select;
    if (document.createRange) {
        range = document.createRange();
        range.selectNode(target)
        select = window.getSelection();
        select.removeAllRanges();
        select.addRange(range);
        document.execCommand('copy');
        select.removeAllRanges();
    } else {
        range = document.body.createTextRange();
        range.moveToElementText(target);
        range.select();
        document.execCommand('copy');
    }
}
1 Like

When you post code on the forums, you need to format it so it will display correctly. You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.

1 Like

Hi there @kingduenas22. I’m glad to hear you’ve found the answer. I have to say I find the title a little confusing, as the whole point of a radio button is that you can’t select more than one. :upside_down:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.