javascript - How to convert dropdown to radio using jquery -


i have drop down select , want change radio button:

html

<select id="designation" title="designation" name="designation">     <option value="">choose option..</option>     <option value="1">educator</option>     <option value="2">student subscriber</option>     <option value="3">adult subscriber</option> </select> <div id="r"></div> 

i try add code display buttons without labels, how can add labels too?

jquery

jquery("#designation option").each(function(i, e) {     jquery("<input type='radio' name='r' />")         .attr("value", jquery(this).val())         .attr("checked", == 0)         .click(function () {             jquery("#designation").val(jquery(this).val());         })         .appendto("#r"); }); 

you have create separately,

jquery("#designation option").each(function(i, e) {   (jquery("<input type='radio' name='r' />")     .attr("value", jquery(this).val())     .attr("checked", == 0)     .click(function() {       jquery("#designation").val(jquery(this).val());     }).add($("<label>"+ this.textcontent +"</label>")))     .appendto("#r"); }); 

demo


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -