I have this select-box
I just add it via jQuery
:
<span onclick="createProduct()">Add New<i class="fa fa-plus"></i></span>
<script>
function createProduct() {
var html = '';
html += ' <div class="col-xs-12">';
html += ' <div class="form-group">';
html += ' <div class="input-group">';
html += ' <span class="input-group-addon input-group-addon-small"><i class="sicon-tag-special"></i></span>';
html += ' <select class="form-control" name="category_id" style="width: 100%">';
html += ' <option value="">Select Category.. </option>';
html += ' <option value="">Category1</option>';
html += ' <option value="">Category2</option>';
html += ' </select>';
html += ' </div>';
html += ' </div>';
html += ' </div>';
$('#products_div').prepend(html);
}
</script>
Here when the Admin clicks on the add new
button, a select element is added in the page. My problem is with creating the the options in the select element. I have this foreach I need to put it into this js code!
@foreach($categories as $category)
<option value="{{ $$category->id }}">{{ $category->name }}</option>
@endforeach