lulu50
asked on
How to submit a form into a new window?
I need your help
How can I submit a form into a new popup window?
this is my form submission
Thanks,
Lulu
How can I submit a form into a new popup window?
this is my form submission
$('form#PCADetailForm').submit();
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var targetWin = window.open('EditDetailInfo.cfm?' , 'Group' , 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
Thanks,
Lulu
you can submit...
set target of your form to the new window name!
see my demo: https://jsfiddle.net/77c80ccp/
set target of your form to the new window name!
var myWindow = window.open(...);
myForm.target="myWindow"
myForm.submit();
see my demo: https://jsfiddle.net/77c80ccp/
ASKER
I can open the pop up window but the form submission is not working
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var myWindow = window.open('EditDetailInf o.cfm?' , 'Group' , 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
myForm.target="myWindow"
myForm.submit();
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var myWindow = window.open('EditDetailInf
myForm.target="myWindow"
myForm.submit();
ASKER
PCADetailForm.target="myWi ndow"
PCADetailForm.submit();
PCADetailForm.submit();
it should be like this (my first post is not working as intended)
https://jsfiddle.net/6af30d7z/
when it runs, it will open a blank window, and submit form to new window...
I am posting 'q=HainKurt' to google and it will show search results...
second parameter, myWindow, is the name of window and can be targeted...
var myWin = window.open("about:blank", "myWindow");
and myWin is window object so you can use it in your javascript code, close later maybe like
JavaScript Window - The Browser Object Model
https://www.w3schools.com/js/js_window.asp
https://jsfiddle.net/6af30d7z/
<form name=myForm action="http://google.ca/search">
<input name=q value='HainKurt'>
</form>
var myWin = window.open("about:blank", "myWindow");
myForm.target = "myWindow"
myForm.submit();
when it runs, it will open a blank window, and submit form to new window...
I am posting 'q=HainKurt' to google and it will show search results...
second parameter, myWindow, is the name of window and can be targeted...
var myWin = window.open("about:blank",
and myWin is window object so you can use it in your javascript code, close later maybe like
myWin.moveTo(...); //move the current window
myWin.resizeTo(...); //resize the current window
...
myWin.focus();
...
myWin.close();
...
JavaScript Window - The Browser Object Model
https://www.w3schools.com/js/js_window.asp
You can do like this
target name must be the same as the second parameter in the window.open.
target name must be the same as the second parameter in the window.open.
<form action="YOURTARGETSCRIPT.php" method="post" target="group">
What is your name ? : <input type="text" name="fullname" />
<input type="submit" />
</form>
jQuery$(function() {
$('form').submit(function() {
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var win = window.open('', 'group', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
});
});
Working sample here
ASKER
I'm not sure what I'm doing wrong
function EditRecord(Group,SEQ_NO,Fi eld,Func,V alue1,Valu e2,DataTyp e)
{
alert("hello");
var page = '<cfoutput>#Defaultpage#</ cfoutput>' ;
$("#HdnGroup").val(Group);
$("#HdnSeqNo").val(SEQ_NO) ;
$("#HdnField").val(Field);
$("#HdnFunction").val(Func );
$("#HdnValue1").val(Value1 );
$("#HdnValue2").val(Value2 );
$("#HdnDataType").val(Data Type);
$('form#PCADetailForm').su bmit(funct ion() {
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var win = window.open('EditDetailInf o.cfm','gr oup','tool bar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
});
}
<FORM id="PCADetailForm" NAME="PCADetailForm" METHOD="POST" ACTION="EditDetailInfo.cfm " target="group">
</FORM >
__________________________ __________ ________
<button name="EditDetailBtn" id="EditDetailBtn" type="button" style="border: 0; background: transparent;cursor:pointer ;" onClick=" return EditRecord('#DetailList.PC AC_GROUP#' ,'#DetailL ist.PCAC_S EQ_NO#','# DetailList .PCAC_FIEL D#','#Deta ilList.PCA C_FUNC#',' #DetailLis t.PCAC_VAL UE1#','#De tailList.P CAC_VALUE2 #','#Detai lList.PCAC _DATA_TYPE #');" >
<img src="../images/EditPencil_ Icon.png" width="18" height="18" alt="Edit Record" style="cursor:pointer;" />
</button>
function EditRecord(Group,SEQ_NO,Fi
{
alert("hello");
var page = '<cfoutput>#Defaultpage#</
$("#HdnGroup").val(Group);
$("#HdnSeqNo").val(SEQ_NO)
$("#HdnField").val(Field);
$("#HdnFunction").val(Func
$("#HdnValue1").val(Value1
$("#HdnValue2").val(Value2
$("#HdnDataType").val(Data
$('form#PCADetailForm').su
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var win = window.open('EditDetailInf
});
}
<FORM id="PCADetailForm" NAME="PCADetailForm" METHOD="POST" ACTION="EditDetailInfo.cfm
</FORM >
__________________________
<button name="EditDetailBtn" id="EditDetailBtn" type="button" style="border: 0; background: transparent;cursor:pointer
<img src="../images/EditPencil_
</button>
ASKER
Julian
your example is what I want to do but I'm not sure what I'm doing wrong.
the other way to do this is to create a session or cookies to pass my parameter from the parent form into the child form.
your example is what I want to do but I'm not sure what I'm doing wrong.
the other way to do this is to create a session or cookies to pass my parameter from the parent form into the child form.
ASKER
I need to keep the form like this
<FORM id="PCADetailForm" NAME="PCADetailForm" METHOD="POST" ACTION="" >
because it is used when I delete a record
<FORM id="PCADetailForm" NAME="PCADetailForm" METHOD="POST" ACTION="" >
because it is used when I delete a record
So where is the form action defined?
ASKER
in the window.open('EditDetailInfo.cfm','_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
ASKER
do I need something like this?
$("#PCADetailForm").attr(" action","E ditDetailI nfo.cfm?pa ge=" + page);
$('form#PCADetailForm').su bmit(funct ion() {
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var win = window.open('','_blank','t oolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
});
$("#PCADetailForm").attr("
$('form#PCADetailForm').su
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var win = window.open('','_blank','t
});
I am trying to find out why your action is not being set in the form?
Can you explain a bit more on what you are trying to do. We can make it work but it sounds like a hack - I would like to understand your requirement a bit better so I can suggest the right way forward.
Can you explain a bit more on what you are trying to do. We can make it work but it sounds like a hack - I would like to understand your requirement a bit better so I can suggest the right way forward.
ASKER
Julian,
On the parent form I created a hidden fields with some values based on the user record selection.
I pass the those values thru my javascript function called EditRecord().
In that function I store my values in my hidden field then I need to submit my form to my pop up window so I can retrieve the values.
On the parent form I created a hidden fields with some values based on the user record selection.
I pass the those values thru my javascript function called EditRecord().
In that function I store my values in my hidden field then I need to submit my form to my pop up window so I can retrieve the values.
Can you not pass the values to the popup using query parameters?
open the window with a URL that has the parameters included - the receiving script sends back the data as required
open the window with a URL that has the parameters included - the receiving script sends back the data as required
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
did you try the code I posted?
$('form#PCADetailForm').submit(function() {
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var myWin = window.open('about:blank','myWindow','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
this.target = "myWindow";
});
I tried this on jsFiddle and no issues
* I cannot save it, some issues with jsFiddle.net
<form id=PCADetailForm action="http://google.com/search">
<input name=q value="HainKurt">
<button type=submit>save</button>
</form>
$('form#PCADetailForm').submit(function() {
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var myWin = window.open('about:blank', 'myWindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
this.target = "myWindow";
});
* I cannot save it, some issues with jsFiddle.net
@HK,
That does not set the action and it is essentially a duplicate of this answer
That does not set the action and it is essentially a duplicate of this answer
in that demo, action is already set to "http://google.com/search"
did you try the demo?
and it is modified version of ID: 42282291, based on the code author has now...
my demos are live and evolving :)
did you try the demo?
and it is modified version of ID: 42282291, based on the code author has now...
my demos are live and evolving :)
ASKER
I finally got it to work based on Julian example.
Thank you all for your help
Thank you all for your help
ASKER
Thank you!!!
It works great!!!!
Thank you Thank you and Thank you
It works great!!!!
Thank you Thank you and Thank you
You are welcome.
ASKER
I need the form value in the pop up.
var w = 600;
var h = 300;
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 4;
var targetWin = window.open('EditDetailInf