?
Solved

popup window on form clears data after submit

Posted on 2003-03-31
11
Medium Priority
?
424 Views
Last Modified: 2013-12-24
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?
0
Comment
Question by:dev12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 10

Expert Comment

by:substand
ID: 8240428
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);"

0
 
LVL 11

Expert Comment

by:hart
ID: 8243368
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
0
 
LVL 11

Expert Comment

by:hart
ID: 8251377
hello did u solve it??

Regards
Hart
0
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 

Author Comment

by:dev12
ID: 8253032
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!
0
 
LVL 10

Expert Comment

by:substand
ID: 8258105
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?

0
 
LVL 11

Expert Comment

by:hart
ID: 8259778
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
0
 

Author Comment

by:dev12
ID: 8261063
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?
0
 
LVL 2

Accepted Solution

by:
jalpino earned 300 total points
ID: 8267093
Here is a simple example of how you can 'preserve' the values of your form variables after you submit them using the post method.


<!--- :: FORM PAGE :: myform.cfm --->

<!--- Initialize your form variables --->
<cfparam name="form.fname" default="">
<cfparam name="form.lname" default="">
<cfparam name="form.age" default="0">

<html>
<head>
     <title> My form </title>
</head>
<body>

<!--- Display your form --->
<table cellspacing="0" cellpadding="3" border="0">
<form name="myForm" action="processingpage.cfm" method="post">
<cfoutput>
<tr>
     <td> First Name </td>
     <td> <input type="Text" name="fname" value="#form.fname#"></td>
</tr>
<tr>
     <td> Last Name </td>
     <td> <input type="Text" name="lname" value="#form.lname#"></td>
</tr>
<tr>
     <td> Age </td>
     <td>
          <select name="age">
               <cfloop from="18" to="55" index="i">
               <option value="#i#" <cfif i EQ form.age> selected </cfif>> #i#
               </cfloop>
          </select>
     </td>
</tr>
</cfoutput>
<tr>
     <td colspan=2> <input type="submit" value="Submit"> </td>
</tr>
</form>
</table>

</body>
</html>



<!--- :: Processing Page :: processingpage.cfm --->

<!--- Initialize incoming form variables --->
<cfparam name="form.fname" default="">
<cfparam name="form.lname" default="">
<cfparam name="form.age" default="0">

<html>
<head>
     <title> Sorry </title>
</head>
<body>

Sorry, please return to the form.

<form name="returnForm" action="myform.cfm" method="post">
     <cfoutput>
     <input type="hidden" name="fname" value="#trim(form.fname)#">
     <input type="hidden" name="lname" value="#trim(form.lname)#">
     <input type="hidden" name="age" value="#val(form.age)#">
     </cfoutput>
     
     <input type="submit" value="Click Here to Return to the Form">
</form>

</body>
</html>


Good Luck

Jalpino
0
 
LVL 11

Expert Comment

by:hart
ID: 8267138
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
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10940985
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
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question