Hi guys i have form where i want to show multiple radio buttons.so by default i am showing one radio button with text and gave option as Addother button ..so user can add multiple radio buttons onclick on add option button as per their requirement..
So here is what i have tried.
Answer Section: <div class="custom-control custom-radio" id="add_other">
<div id="container0">
<input type="radio" class="custom-control-input" id="defaultUnchecked" name="defaultExampleRadios">
<input type="search" name="" value="">
</div>
</div>
<div class="custom-control custom-radio" >
<input type="radio" class="custom-control-input" id="defaultUnchecked" name="defaultExampleRadios">
<input type="search" name="" value="">
<button class="remove" onclick="removeDiv(this);">X</button>
</div>
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" id="defaultUnchecked" name="defaultExampleRadios">
<input type="search" name="" value="">
<button class="remove" onclick="removeDiv(this);">X</button>
</div>
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" id="defaultUnchecked" name="defaultExampleRadios">
<input type="search" name="" value="">
<button class="remove" onclick="removeDiv(this);">X</button>
</div>
<div class="custom-control copy-radio" onclick="addoptions()">
<label class="add_option" id="add_othe1r">Add More</label>
</div>
</div>
Script code:
var index = 3;
function addoptions() {
$('#add_other').append(`<div id="container${index}" >` + '<input type="radio" class="custom-control-input" name="defaultExampleRadios"/ >' + `<input type="search" name="text"/>` + "</div>");
index ++;
}
function removeDiv(btn){
((btn.parentNode).parentNode).removeChild(btn.parentNode);
}