dongzhiji0814 2013-10-24 16:23
浏览 23
已采纳

为什么我的弹出窗体没有被帖子数据填充

I have a scheduling application that users can click on a table field and it will open a form in a new page with the appropriate post data. My users have decided that this is much to difficult and now require to see the schedule and that the form be a popup window so they can see both at the same time. I have the form popup working, but my function is not passing the post data. This is the code:

$(".main td:not(.jobCell):not(.tJCell)").click(function()
{
    var roleID = document.getElementById('roleID').value;
    var notDept =  $('.deptSelect').val();
    var myDept = $('#myDept').val();
    var $this = $(this);
    var colIndex = $this.cellPos().left;
    var preCol = colIndex % 2;

        if (myDept != notDept)
        {
            return;
        }


    if (preCol == 0)
    {
        colIndex = colIndex /2;
    }
    else
    {
        colIndex++;
        colIndex = colIndex /2;
    }

    var row = $this.parent('tr').contents('th:eq(0)').html();
    var departmentID = $(".deptSelect").val();  
    var headerObj = $(this).parents('.main').find('th').eq(colIndex);
    var toPass =   $.trim(headerObj.text());
    var picked = $("#picked").val();
    var testDate = new Date(picked + " " + row);
    var today = new Date();
    var today = new Date(today - 2*60*60*1000);


    if (testDate < today)
    {
        if (roleID > 2)
        {
        alert (today);
        alert("You Cannot Schedule a New Job in the Past!");
        }
        return;
    }
    var thisForm = '';

    if (roleID == 5)
    {
        thisForm = '../forms/tentativeJobForm.php';
    }
    else
    {
        thisForm ='../forms/newJobForm.php';
    }

    var f = document.createElement("form");
    f.setAttribute('class','jobTime');
    f.setAttribute('method','post');
    f.setAttribute('action',thisForm);

    var iii = document.createElement('input');
    iii.setAttribute('type','hidden');
    iii.setAttribute('name','departmentID');
    iii.setAttribute('value',departmentID);
    f.appendChild(iii);

    var i = document.createElement('input');
    i.setAttribute('type','hidden');
    i.setAttribute('name','sTime');
    i.setAttribute('value',picked + " " + row);
    f.appendChild(i);

    var ii = document.createElement('input');
    ii.setAttribute('type','hidden');
    ii.setAttribute('name','ast');
    ii.setAttribute('value',toPass);
    f.appendChild(ii);

    document.getElementsByTagName('body')[0].appendChild(f);
    if (roleID > 2)
    $('.jobTime').onsubmit(window.open(thisForm,null,"height=550,width=900,toolbar=0,menubar=0,location=100,status=no,scrollbars=1,resizable=1,right=300,top=100"));
    //$('.jobTime').submit();
    else
    return;
});

I know the function is not posting the data, so my question is 'how do I get the function to open the popup form with the post data?'

  • 写回答

1条回答 默认 最新

  • dsh125986083 2013-10-24 17:16
    关注

    The form being submitted and your window.open() function call are two different requests to the same page, one in the same window and one in a new window. Your post data gets sent, but not to the new window you open.

    The easiest thing to do would be to open the window first and send your post data to it by giving it a name, then telling the form to target the new window.

    Open the window before you submit the form:

    window.open("","mynewwindow","height=550,width=900,toolbar=0,menubar=0,location=100,status=no,scrollbars=1,resizable=1,right=300,top=100");
    

    Give the form a target:

    f.setAttribute('target','mynewwindow');
    

    To be more fancy and elegant you could use the jquery load() function to open the form in part of the current page. You wouldn't need to create the form element in html that way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗