dongre9937 2013-12-22 08:05
浏览 123
已采纳

on dropdown从数据库和填充文本框更改事件加载数据

I have a simple dropdown list, whose values are from the DB.I am doing it as

$query = "SELECT id,location_name FROM misc_location";
if ( $result = mysql_query($query) ) {
    $selectLoco = "<select name='selectLoco' id='selectLoco'>";
     while ($row = mysql_fetch_row($result) ) {
        $selectLoco .= "<option value='$row[0]''> $row[1] </option>";
     }
     $selectLoco .= "</select>";
} 

But now i have a text box below the dropdown. So when user selects a dropdown item ,I need to pull a value corresponding the item selected and display in the text box.

Table : misc_location

id   location_name   time
1    Ben             7.00 am
2    Cat             8.00

Location : Drop-down user selects Ben , Text box below should display 7.00

  • 写回答

4条回答 默认 最新

  • douzhang7603 2013-12-22 17:42
    关注

    I got a work around , based on the answers using ajax + json here its how i did it

    The jquery

    $('#selectLoco').on('change', function(){
        selectLoco = $('#selectLoco option:selected').val(); // the dropdown item selected value
        $.ajax({
            type :'POST',
            dataType:'json',
            data : { selectLoco : selectLoco },
            url : 'getresult.php',
            success : function(result){
             $('#textBoxIwant).val(result['WeekDaySm']);// json result      
            }
        });
    
    });
    

    The PHP

    <?php 
    require_once ('../config/db.config.php');
    
    $selectLoco = $_POST['selectLoco'];
    $query = "SELECT * FROM misc_location WHERE id = '$selectLoco' ";
    
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);
    echo json_encode($row);
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错