-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.

2
  • 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. Commented Sep 23, 2015 at 22:52
  • If IE is in your browser compatibility list do take a look at this: stackoverflow.com/questions/2566394/… Commented Sep 24, 2015 at 0:17

3 Answers 3

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

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

JSFiddle

Sign up to request clarification or add additional context in comments.

2 Comments

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.
@JoshuaDannemann - agreed. My answer is generic and would not work in all cases.
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");

1 Comment

Thx for your help. Works
0

Just change the type of your inputs.

$(':radio').each(function(){
    $(this).prop("type","checkbox");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.