can someone teach me on how to auto fill an select box based on the selection from the other select box?
this is my first selection wherein the user will select in Orderlist Code.
<div class="form-group">
<label for="gross_amount" class="col-sm-2 control-label" style="text-align:left;">OL Code</label>
<div class="col-sm-6">
<select class="form-control" id="table_name" name="table_name">
<?php foreach ($orderlist_data as $key => $value): ?>
<option value="<?php echo $value['id'] ?>"><?php echo $value['ol_code'] ?></option>
<?php endforeach ?>
</select>
</div>
</div>
after the selection base on the Order list code i hope to auto fill this selection base on the selection in the orderlist code.
create.php
<select class="form-control select_group product" data-row-id="row_1" id="product_1" name="product[]" style="width:100%;" onchange="getProductData(1)" required>
<option value='maincat' selected>--Select Products--</option>
<?php foreach ($products as $k => $v): ?>
<option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
<?php endforeach ?>
</select>
edit.php
<select class="form-control select_group product" data-row-id="row_<?php echo $x; ?>" id="product_<?php echo $x; ?>" name="product[]" style="width:100%;" onchange="getProductData(<?php echo $x; ?>)" required>
<option value=""></option>
<?php foreach ($products as $k => $v): ?>
<option value="<?php echo $v['id'] ?>" <?php if($val['product_id'] == $v['id']) { echo "selected='selected'"; } ?>><?php echo $v['name'] ?></option>
<?php endforeach ?>
</select>
here is an photo on the orderlist module
then i hope someone can teach me how to auto-fill the product selection based in the orderlist selection
if i press the "OLCODE-1E6E" in the orderlist code selection i want to automate my product selection and display the 2 items i set in the orderlist but does not have knowledge from it i hope someone can teach.
function getProd(row_id)
{
var orderlist_id = $("#olcode_"+row_id).val();
if(orderlist_id == "") {
//i don't know the correct way
} else {
$.ajax({
url: base_url + 'orderlist/getOrderListById',
type: 'post',
data: {orderlist_id : orderlist_id},
dataType: 'json',
success:function(response) {
//i don't know the correct way
}
});
}
}
2
Answers
I think you can use the jquery autocomplete ui along with php to return all the values. If it doesn’t work with the
<select>
tag then just swap it with an<input>
so the user can type in the product and use the list of autocompletions to help.I hope that is helpful.
You can do it like this:
Then, just type "ja" and java and javascript should appear below as options.
Use some php code to get the list of options.
You can then use bootstrap or php to make sure they typed a valid product.
Bootstrapv Validation