Why The Select Option Didn't Showing Number?

 ̄綄美尐妖づ 提交于 2020-07-07 09:56:41

问题


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


回答1:


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>";
}



回答2:


try this, and see if it works or the values printed in the browser console are what you expect them to be.

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 (product_stock == "stock_m") {
          disable_values(stockm); //add till this option

        } else if(product_stock == "stock_l") {
        disable_values(stockl); //add till this option
        }

      }


      function disable_values(end) {
        console.log(end)
        var gets = document.getElementById("product_stock");
        var data="";
        var limbuy = "<?php echo $stock['minorder'];?>";

        for (var i = limbuy; i <= end; i++) {

        data +="<option value="+i+">"+i+"</option>";
        console.log(i)
        }

       gets.innerHTML= data;
        
      }




回答3:


<div class="form-group form-md-line-input form-md-floating-label">
    <select class="form-control edited" name="rating" id="form_control_1">
      <option value="<?php echo $manage->rating;?>"><?php echo $manage->rating;?></option>
      <option value="0.5">0.5</option>
      <option value="1">1</option>
      <option value="1.5">1.5</option>
    </select>
</div>


来源:https://stackoverflow.com/questions/62668591/why-the-select-option-didnt-showing-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!