How to change input type dynamically using jquery or javascript -
below html code:
<input type="checkbox" id="multioptions" />isformultioptions <input type="radio" value="1" name="option">option1 <input type="radio" value="2" name="option">option2 if select checkbox i.e. multioptions radio buttons should convert checkboxes. , if uncheck checkbox i.e. multioptions checkboxes should convert in radio buttons. in advance.
you'll need remove , recreate elements, because ie doesn't let change type of input after it's created.
jquery makes easy replacewith:
$("selector input change").replacewith('<input type="checkbox">'); so instance:
$('input[type="radio"][name="option"]').each(function() { $(this).replacewith('<input type="checkbox" name="option" value="' + this.value + '">'); }); or if values may contain characters requiring entities:
$('input[type="radio"][name="option"]').each(function() { var rep = $('<input type="checkbox" name="option">'); rep.attr("value", this.value); $(this).replacewith(rep); });
Comments
Post a Comment