duanhe6799 2012-11-05 06:48
浏览 51
已采纳

如何从URL中的单独表单传递值与JQuery一起?

I have a separate form in the php page which also has Jquery jtable plugin to display data from Mysql database. The form has a drop down list boxes. i have to pass the values from those dropdown along with the Jtable action List in the url, to list table with respect to the condition selected from the drop down.

   <div id="machinelog">
    <form id="intermediate" name="inputMachine" method="post">
    <select id="selectMachine" name="selectMachine"> 
        <option value="M1" >Machine 1</option>
        <option value="M2" >Machine 2</option>
        <option value="M3" >Machine 3</option>
    </select>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


<input id="Button" class="button" type="submit" value="Submit" />
</form>  

If i choose Machine 1 from the dropdown list, i have to make the jtable to display only the rows which has machine as Machine 1.

i have to access the form values inside the Jtable container so that i can pass those valus in the url.

   <div id="MachineLogTableContainer" style="width: 1000px; margin-left: 254px;margin-top: -440px;position: static;"></div>
    <script type="text/javascript">

        $(document).ready(function () {
            //var s=$('#selectMachine').val();
            //alert(s);
            var machineLogMessages = {
                    addNewRecord: '+ New Machine Log'
                };

            //Prepare jTable
            $('#MachineLogTableContainer').jtable({
                messages:machineLogMessages,
                title: 'Machine Log',
                paging: true, //Enable paging
                pageSize: 10,
                actions: {
                    listAction: 'MachineLogActions.php?action=list',
                    createAction: 'MachineLogActions.php?action=create',
                    updateAction: 'MachineLogActions.php?action=update',
                    deleteAction: 'MachineLogActions.php?action=delete'
                },
                fields: {
                    event_id: {
                        key: true,
                        edit: false,
                        title: 'Event Id',
                        width: '5.8693%',
                        create:false,
                        edit:false,
                        list: false
                    },
                    event_type: {
                        title: 'Event Type',
                        width: '9%',
                        options: 'MachineLogActions.php?action=list_type'
                    },
                    machine: {
                        title: 'Machine',
                        width: '16%',
                        options: 'MachineLogActions.php?action=list_name'
                    },
                    user: {
                        title: 'User',
                        width: '11%',
                        options: 'MachineLogActions.php?action=list_user'
                    },
                    timestamp: {
                        title: 'Timestamp',
                        width: '15%'
                    },
                    shift: {
                        title: 'Shift',
                        width: '9%',
                        options: 'MachineLogActions.php?action=list_shift'
                    },
                    reason: {
                        title: 'Reason',
                        width: '25%',
                        options: 'MachineLogActions.php?action=list_reason'
                    },
                    count: {
                        title: 'Count',
                        width: '3%'
                    }
                }
            });

            //Load person list from server
            $('#MachineLogTableContainer').jtable('load');

        });

    </script>

once i press the submit button, my listing url should also contain the machine value.

        listAction: 'MachineLogActions.php?action=list&MachineId=',+machineId

Is it possible in Jquery.

I tried like this

    var s=$('#selectMachine').val();
alert(s);

i get the following error in chrome

    Uncaught SyntaxError: Unexpected token ,
  • 写回答

2条回答 默认 最新

  • dongyong6428 2012-11-09 05:05
    关注

    This thing solves my problem of filtering.

                select = document.getElementById("selectShift");
                select.onchange = function(){
                    //alert(this.value); 
                    //alert(this.innerHTML); 
                var options = this.getElementsByTagName("option");
                optionHTML = options[this.selectedIndex].innerHTML;  
    
                $('#ShiftLogTableContainer').jtable('load', {
                    ShiftId: optionHTML
                    });
                };
    

    you should add it instead of

      $('#MachineLogTableContainer').jtable('load');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离