i have some problems. Where my stock produk size is “100-199” The Select Option just showing this :
If in my product have stock is 1-99 and 200-999 i didn’t get this error. The select option is fine and showing a number. In my case stok s and stok m the select option showing the number.
This my db :
This is my Controller :
$data['stock'] = $this->Product_model->get_product_all($id);
This is my Models :
public function get_product_all($id){
$this->db->select('products_shirt.*');
$this->db->from('products_shirt');
$query = $this->db->get();
return $query->row_array();
This is view code :
<select name="product_size" id="product_size" class="form-control" onchange="proses_stock()" style="width:95%">
<option value="0">Select Size:</option>
<option value="stock_s">s</option>
<option value="stock_m">m</option>
<option value="stock_l">L</option>
</select>
<select name="product_stock" id="product_stock" class="form-control" style="width:95%">
<option value="0">0</option>
</select>
This is JavaScript Code :
function proses_stock() {
var product_stock = document.getElementById("product_size").value;
var stocks = "<?php echo $stock['stock_s'];?>";
var stockm = "<?php echo $stock['stock_m'];?>";
var stockl = "<?php echo $stock['stock_l'];?>";
if(product_stock == "0") {
document.getElementById("product_stock").innerHTML = "<option value='0'>0</option>";
} else if (product_stock == "stock_s") {
disable_values(stocks); //add till this option
} else if (produk_stock == "stock_m") {
disable_values(stockm); //add till this option
} else {
//if large size select
//do somthing ..
disable_values(stockl); //add till this option
}
}
function disable_values(end) {
var gets = document.getElementById("product_stock");
var data="";
var limbuy = "<?php echo $stock['minorder'];?>";
var limbuys = 4;
//loop through all options
//for (var i = limbuys; i <= end; i++) {
for (var i = limbuy; i <= end; i++) {
//append options
data +="<option value="+i+">"+i+"</option>";
}
//add data to select box
gets.innerHTML= data;
}
When i’m use var limbuys
so var i = limbuys;
i get the normal way, and if i change with var limbuy
so var i = limbuy;
and get data number from database minorder
i’m find this problem. And the problem just if example “in stok L just have 100-199 stock” i get this error(look picture). and if i pick size s (max stock 80) or size m (max stock 250) and im using limbuy
its fine, why?
I’m using codeigniter with bootsrap. Thanks for help
Advertisement
Answer
This is happen because your limbuy
and your end
is a string
you can try use
for (var i = parseInt(limbuy); i <= parseInt(end); i++) {
data +="<option value='"+i+"'>"+i+"</option>";
}