-2

PS: Problem solved. Thx all you guys.

I need to change radio button to checkbox when page loading.

I can not make the checkbox directly, so I have to find a way to solve this.

I've tried How can I change a checkbox for a radio button using jQuery?, but got errors like replace is not a function or undefined.

Community
  • 1
  • 1
TODD_Syd
  • 71
  • 2
  • 10
  • 3
    Please add some code to show what you have tried already. it is much easier to help you if we can start from what *isn't* working. – duncanhall Sep 23 '15 at 22:52
  • If IE is in your browser compatibility list do take a look at this: http://stackoverflow.com/questions/2566394/changing-the-input-type-in-ie-with-javascript – PeterKA Sep 24 '15 at 00:17

3 Answers3

1
$(':radio').attr('type','checkbox')

No need to iterate with "each". The selector selects all radios.

JSFiddle

devlin carnate
  • 8,309
  • 7
  • 48
  • 82
  • 1
    Wish he had posted some code. In many cases, you cannot just change every radio button on a page to a checkbox, and if the element has not been created yet, then trying to change it will fail. – Joshua Dannemann Sep 23 '15 at 23:02
  • @JoshuaDannemann - agreed. My answer is generic and would not work in all cases. – devlin carnate Sep 24 '15 at 14:29
0

The answer to this question depends a lot on where and when you can insert a script. If the script runs before the element is loaded into the page, then you will not be able to find it because it does not yet exist. However, if you are able to load the script inside the body either before or after the element has loaded, you can run a function with the body onload event (if before the element is created) or you can run it as the page is loading if the element has been created. Not withstanding the question of what code you need to garner a DOM reference to the element, the rest is easy. You just change the attribute on the element in question.

$("#foo").attr("type", "checkbox");
Joshua Dannemann
  • 2,003
  • 1
  • 14
  • 34
0

Just change the type of your inputs.

$(':radio').each(function(){
    $(this).prop("type","checkbox");
});
Franklin Satler
  • 320
  • 1
  • 7