0

我想说的是:当您单击下拉菜单或选择时,它将获取 prod_temno、prod_desc、prod_selluom 的数据,然后填充到名为:idesc 和 inventoryuom 的文本框。我希望你能帮助我。提前致谢。

 <table>
    <tr><form name="form1">
        <td>Item No:</td>
        <td>
        <select type="text" id="inventoryitemno" name="inventoryitemno" >
            <?php
                foreach($itemno as $row){
                    echo "<option id=".$row->prod_id.">".$row->prod_itemno."</option>";
                }
            ?>               
        </select>                                
        </td>
    </tr>
    <tr>
        <td>Description:</td>
        <td><input type="text" id="idesc" name="idesc"/></td>  
    </tr>
     <tr>
        <td>UOM:</td>
        <td><input type="text" id="inventoryuom" name="inventoryuom" /></td>
    </tr>

</table>

这是我的 products_model

    public function view_product_itemno(){
        $this->load->database();
        $data = $this->db->query('select prod_id, prod_itemno, prod_desc, prod_inventoryuom from product;');
        return $data->result(); 
    }

我希望这对你们来说很清楚。谢谢。

4

3 回答 3

0

这是你想要的吗?

<?php
$itemno = array('0'=>'a','1'=>'b','2'=>'c');

?>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js" ></script>
<table>
<tr><form name="form1">
    <td>Item No:</td>
    <td>
    <select type="text" id="inventoryitemno" name="inventoryitemno"  onchange="javascript:set_to(this.value);" >
         <?php
             foreach($itemno as $key=>$val){
                echo "<option id=".$key.">".$val."</option>";
            }
        ?>               
    </select>                                
    </td>
</tr>
<tr>
    <td>Description:</td>
    <td><input type="text" id="idesc" name="idesc"/></td>  
</tr>
 <tr>
    <td>UOM:</td>
    <td><input type="text" id="inventoryuom" name="inventoryuom" /></td>
</tr>

</table>
<script type="text/javascript">
function set_to(id)
{

    $('#idesc').val(id);
}
</script>
于 2013-06-18T04:27:02.587 回答
0
What about "<DATALIST>"?

<input type=text name='somename' list='somelist'>
<datalist id="somelist">
<option value=1>One</option>
.
.
<option value=99>Ninety-Nine</option>
</datalist>

You can even fill the list from a DB with mysql
<datalist = id=somelist>
<?
$sql="select * from my_table";
$rs=mysql_query($sql,$mysql_connection);
$row=mysql_fetch_assoc($rs);
do {
 printf("<option value='%s'>",$row['some_field'])}
while($row=mysql_fetch_assoc($rs));

Hope that helps.
于 2013-11-26T03:48:57.380 回答
0

您也可以参考此链接-> chaneg event

我假设当有人更改选择框时您必须调用该函数。您必须通过 ajax 调用模型,然后将响应放入文本框中:-

$('#inventoryitemno').change(function() 
{   

   // write ajax code and call your model and dump the result into your textbox

    $.ajax({
     type:"POST",
     data:"value="+$(this).val(),
     url:"your_controller_path",
     success:function(msg)
     {
        $('#idesc').val(msg);
     }

  });



});

您的控制器应该是这样的,说控制器名称是 product_controller :-

function product_details()
{
   $value = $this->input->post('value'); // value from ajax

   $this->products_model->products_model($value);

   echo "response"; //return the result back to ajax success function

}
于 2013-06-18T04:24:24.787 回答