Link to home
Start Free TrialLog in
Avatar of dev12
dev12

asked on

popup window on form clears data after submit

I have a button on a search filter form that opens a popup window listing several hundred companies for the user to pick from.  The popup window populates a few of the fields on the opener window's form before closing.  A popup is really necessary here instead of a select field because the user's selection is based on several pieces of information about a company.  Error checking is done on the actual submission page, and if errors are encountered, a message is displayed directing the user to go back and correct input.  

Here is the problem: if the button for the popup window is clicked before the form is submitted and the back button is used to return to the form for corrections, all previous input has been cleared.  (If the popup is not used and back is clicked, the previous input is still there.)  CFForm attribute preservedata doesn't work.  Anyone know a way to keep the data on the form if a popup is used?
Avatar of substand
substand

are you using your own coded "back" button?

if so, don't let it "submit" the form, make it's onclick attribute like

onclick="history.go(-1);"

for preventing the main form from loosing data do the following.


Main form with pop up button/image

<form name="mainfrm" method="post" action="somepage.cfm">
form elements
<input type="text" name="somename" value="">

for popping up using image
<A href="javascript:callme()"><img src="image path" alt="Pop Up" border="0"></A>

for popping up using button
<input type="button" name="popme" value="Pop Up" onclick="javascript:callme()">

</form>


now put a anther form after main form(mainfrm)
<form name="subfrm" action="popuppage.cfm" target="popupwinname" method="post">
put hidden fields like
<input type="hidden" name="hiddenname" value="">
</form>

now on the top put this javascript function
<script language="javascript">
function callme()
{
//assign required fields from mainfrm to subfrm. i.e
document.subfrm.hiddenname.value=document.mainfrm.somename.value;
window.open('popuppage.cfm','popupwinname','specify window properties like height,weight etc..')
document.subfrm.submit();
}
</script>


This way only the subfrm will be submitted to the pop up with required values.

And the main frm will remain as it is.

Hope this helps

Regards
Hart
hello did u solve it??

Regards
Hart
Avatar of dev12

ASKER

hart -- Your suggestion did not work.  The data doesn't disappear after the popup is used, but after the form is submitted and then the back button is used to return to the form.  I have no clue what to do.  Using preservedata doesn't work, having the popup reload the input field values as it closes doesn't work.

Anyone who knows anything about this, help!
could you possibly use session vars to keep track of what the form values were, then use like

<cfif isdefined("session.fieldname")>value="#session.fieldname#"</cfif>

on the fields?

from the pop up don't sumbit the page to the main form.

Just assign those values to the main form elements.

i hope we wre both thinking the same..


1. You have a main form.
2. from which for some of the values you pop up a screen and select some values which will be automatically assigned to the main form

for this use window.opener.mainformname.fieldname.value=document.popupformname.fieldname.value and put this code onsubmit of the pop up form.


3. Then You just submit the main form.

Thatz it right..?

Regards
Hart
Avatar of dev12

ASKER

substand - I can't use the session variables because sometimes the form needs to come up filled out by a query for an existing database entry, sometimes blank for a new database entry.

hart - My popup window doesn't submit to the main form.  We are thinking along the same lines, and the popup simply assigns the values to the correct fields on the main form before it closes.  

This is the problem:  The user clicks on the button to open the popup, chooses something from the popup, and submits the main form.  If there is a data error (incorrect date or something), the submission page will display a message for the user to go back and correct the data.  On clicking the browser's back button, all input that was on the form is now gone.  It's not that the data disappears when the popup closes, but when the back button has to be used to get back to the form after submission.

The only thing I can think of is to do all data validation in javascript so that the back button will never need to be used after form submission.  Any other suggestions?
ASKER CERTIFIED SOLUTION
Avatar of jalpino
jalpino

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok the only solution that i can think of is to send ll the values submitted back to the same page using hiddenfileds.

and check for existence in the main form and show the value.

i.e
<input type="text" name="somename" <cfif isdefined('hiddenvariablename')>value="#hiddenvariablename#"<cfelse>value=""</cfif>>


or you can put javascript checks before submitting to check for appropraite data to be submitted..

Regards
Hart
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation in the Cleanup topic area:

Accept jalpino

Please leave any comments here within the next four days.

mrichmon
EE Cleanup Volunteer