How to Submit Parent Window from Child Window...
hi All,
Greetings!
in My parent window, i have around 18-20 fields.
i want to open pop-up from the parent screen but wants these 18-20 fields to be available in my WebAction(Struts FrameWork).
currently i m submitting the child window so i m not getting these fields.
so overall, want to open pop-up but want to submit parent window.
please help me in this for how to sumbit parent window.
Thanks in Advance,
Ashish
# 1
Hi,
From what I understand your requirement is this:
1. Open a child window with some fields which may be edited
2. On submitting the child window, have all the fields available on the parent window
3. Submit the parent window
I haven't used Struts, but I had a similar requirement using JSP and JavaScript. Here's how I solved it, maybe it'll help you:
1. Create the parent window with identical fields as there will be on the child window; but make them of hidden ( or text, as your requirement is ). These are basically placeholders for the values from the child window.
2. In the child window, use the 'opener' property which is a reference to the parent. Put appropriate checks in the 'onload' event of the body to make sure the opener exists and points to the valid JSP
3. On the onclick event of the submit button/ onsubmit event of the form, call a JavaScript function of the opener ( parent ) window to set appropriate values. Or you could directly set the values ( the hidden fields you created as placeholders ) of the parent window.
4. Call a function on the parent to cause the form to submit.
I had a JSP for 'advanced search' as the child where additional fields were available to search for. On clicking search on the child window, I'd cause the parent to submit and run the query.
I'd set values from the parent on the child; you can work the reverse way if you need to:
function setDefaults ()
{
document.getElementById('searchid').value = opener.document.getElementById('searchid').value;
document.getElementById('searchname').value = opener.document.getElementById('searchname').value;
document.getElementById('searchdepartmentid').value = opener.document.getElementById('searchdepartmentid').value
}
On clicking search, I'd call a function on the parent:
<input class="searchbutton" type="button" name="search" value="Search" onclick="opener.advancedSearchClicked();"/>
That function would read the current values of the fields and put them in the hidden fields. I'd maintained a reference to the child window as 'searchWindow' and I use that:
function advancedSearchClicked ()
{
if ( searchWindow == null || searchWindow.closed )
{
return;
}
document.getElementById('searchid').value = searchWindow.document.getElementById('searchid').value
document.getElementById('searchdepartmentid').value = searchWindow.document.getElementById('searchdepartmentid').value;
document.getElementById('searchname').value = searchWindow.document.getElementById('searchname').value;
searchWindow.close();
document.getElementById('search').click();
}
The last statement invoked the click() event of the 'Search' button on the parent window which was a 'Submit' button hence causing the form to submit. I guess you could also directly call the submit() event. Your choice.
Hope this helps.