I have to create a cascade of elements dynamically.
<label class="control-label col-sm-2 text-primary" for="prix">Prix:</label>
<div class="col-sm-10">
<select name="prix" id="prix">
<option value="0">Type de prix</option>
<option value="1">Gratuit</option>
<option value="2">Montant</option>
<option value="3">Echange</option>
<option value="4">Prix à discuter</option>
<option value="5">Prix n'est pas d'application</option>
</select>
</div>
<div id="select_prix" ></div>
<div id="select_offre" ></div>
When I choose option value="2"
, a checkbox have to be inserted into div id="select_prix"
So I use jquery:
$('#prix').on('change', function() {
if ($(this).val() < 2) {
$("#select_prix").empty();
}
var stroffre ='<label class="col-sm-2 control-label text-primary">Offre ? </label>';
stroffre +='<div class="checkbox col-sm-10">';
stroffre +='<label class="checkbox-custom" data-initialize="checkbox">';
stroffre +='<input class="sr-only" id="chkoffre" type="checkbox" value="">';
stroffre +='<span class="checkbox-label">Autoriser les offres</span>';
stroffre +='</label> </div>';
if ($(this).val() == 2) {
$("#select_prix").append(stroffre);
}
});
Ok. The checkbox appears and what I get is:
checkbox ' Autoriser les offres'
Now, when I select checkbox , I want to insert a new line input into div id="select_offre"
I made for that a new jQuery code:
$("#chkoffre").change(function () {
alert( 'CheckboxOffre' ); // or $(this).val()
if($(this).is(":checked")) {
}else{
}
});
Unfortunately, I don't get the alert message.