lundi 3 septembre 2018

How to put the list of dynamically dropdown using javascript and laravel?

I am using Laravel and I have dynamically dropdown using javascript. I have a problem when I have to put the list of dropdown in javascript. I use this code to show list on my laravel view blade :

<select id="sip_material_add" name="sip_material_add" class="selectpicker form-control edit" data-live-search="true" style="width:100%" required> 
    @foreach($material as $getData)
    <option value=""> </option>
    @endforeach            
</select>

And I want it put in the dynamically dropdown like in the picture below.

enter image description here

This is my javascript code for add dropdown dynamically:

$(function () {
    $("#btnAdd").bind("click", function () {
        var div = $("<tr />");
        div.html(GetDynamicMaterial(""));
        $("#TextBoxContainer").append(div);
    });
    $("body").on("click", ".remove", function () {
        $(this).closest("tr").remove();
    });
});

function GetDynamicMaterial() {
    return '<td><select name="ship_material_add" class="form-control">'
         + '<option></option>'
         + '</select></td>'  
         + '<td width="25%"><input name = "ship_quantity_add" type="text" class="form-control" /></td>' 
         + '<td width="15%"><button type="button" class="btn btn-danger remove"><i class="glyphicon glyphicon-remove-sign"></i></button></td>'
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire