Reputation: 107
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?'
Upvotes: 0
Views: 260
Reputation: 342
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.
Upvotes: 1