?
Solved

Lost History On Window.History.Back() -- Javascript and ColdFusion

Posted on 2004-04-22
7
Medium Priority
?
32,255 Views
Last Modified: 2013-12-20
Hello All,

I have a basic ColdFusion form with input boxes and combo boxes. The combo boxes are populated by CF queries. After submittal of the form, I do some server side error checking on the action page. If an error occurs, I display the error to the user and provide a link (simply window.history.back()) for him or her to return to the form to correct data. Sounds simple right? Well, here is where the complication comes in...at least for me anyhow. One of the combo boxes has an "OnChange" event that causes other fields to be populated. If I don't select anything from that combo box and force the error, the history is retained, but if something is selected from that combo box and an error occurs, the history disappears. Not only the combo box info is gone, but all the other information that I filled in as well...just sends me back to a blank form. Any help would be appreciated!

The code is pretty simple on the action page...just the CF validation and the window.history.back(); link. Below is the combo box.

<cfquery name="QRY_JOB_TYPES" atasource="#LAP_DATA_SOURCE#">
SELECT     JOB_TYPE_DESC, DEFAULT_DAYS
FROM     tab_JOB_TYPES
ORDER BY JOB_TYPE_DESC
</cfquery>

<select name="cmb_Type" size="1" onchange="Javascript:PopDates()">
<option value="" selected>
<cfloop query="QRY_JOB_TYPES">
<option value="#QRY_JOB_TYPES.JOB_TYPE_DESC#"><font class="ArialBlk8">#QRY_JOB_TYPES.JOB_TYPE_DESC# (average completion in #QRY_JOB_TYPES.DEFAULT_DAYS# days)</font>
</cfloop>
</select>

<script language="JavaScript">
function PopDates()
     <!--- Opens a popup that displays a please wait message and populates estimated start and end dates based on the job type selected --->
     {
     var typeindex = document.frm_JOB_ADD.cmb_Type.selectedIndex;
    var selectedtype = document.frm_JOB_ADD.cmb_Type.options[typeindex].value;
     var mypath = "JOB_POPULATE_DEFAULT_DATES_AND_USER.cfm?URL_TYPE=" + escape(selectedtype) + "&URL_BEG_DATE=" + escape(document.frm_JOB_ADD.txt_EST_START_DATE.value);
     window.open(mypath+"&random="+Math.random(),"mywin","scrollbars=1,left=190,top=160,width=160,height=80"); <!--- Opens Page And Refreshes Info From Server --->
     }
</script>


Thanks!
0
Comment
Question by:mts9
[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
  • 3
  • 2
  • 2
7 Comments
 

Assisted Solution

by:riffraff5
riffraff5 earned 750 total points
ID: 10888049
when you submit your form, set each form field into a variable before processing any error checking...

<cfset firstname=form.firstname>
<cfset lastname=form.lastname>
etc.

On your form page, check for the existance of the variable to populate the field.

<cfinput type="text" name="firstname" <cfif isdefined("firstname")>value="#firstname#"</cfif> size="30" maxlength="30">

The more proper method is to use cfparam at top of  your form page and default each form field to "".

<cfparam name="firstname" default="">
<cfparam name="lastname" default="">

then set each form field as follows:

<cfinput type="text" name="firstname" value="#firstname#" size="30" maxlength="30">
<cfinput type="text" name="lastname" value="#lastname#" size="30" maxlength="30">

if the user submits the form and the variables are set on your action page as described above, the variables will remain constant regardless of the problems they may encounter.

hope this helps

0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 10888131
>>I do some server side error checking on the action page. If an error occurs, I display the error to the user and provide a link (simply window.history.back()) for him or her to return to the form to correct data

try some client side validation too

<form action="' method="" onSubmit="return validateForm(this);">

<script>

function validateForm(objForm){
var strErr="";
var objFocus="";
if (!objForm.formElement.value){
strErr+="FormElement is blank!\nThis is a required field.")
if(!objFocus){
objFocus=objForm.formElement;
}
..do all validation

if(strErr){
alert(strErr);
objFocus.focus();
}
return !strErr;
}

}

}
0
 

Author Comment

by:mts9
ID: 10888799
All,

Yes, I agree both of these fixes, but I guess I was looking for why my problem is occurring.

Thanks
Mike
0
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 

Expert Comment

by:riffraff5
ID: 10888936
Because you are not providing any way to maintain persistance of the user's inputs.
0
 
LVL 25

Accepted Solution

by:
James Rodgers earned 750 total points
ID: 10888941
>>but I guess I was looking for why my problem is occurring

nature of the web, pages are static and are referenced based on the actual page not dynamic changes made to a page, sometimes you can hit the back button on a browser and the form information will be there but not always and it doesn't seem to be any particular thing that decides it,

what i usually do is submit form pages to themselves, action="" or if the page is called myForm.cfm the form action=myForm.cfm, and at the top of the page
<cfif isDefined("form.submit")> <!--- or some other form field --->
do form processing/validation here

use cflocation, meta tag or window.location to redirect after success
</cfif>
if errors redisplay form with appropriate error message(s) highlighting incorrect fields,

works better than submit to new page and the first time the page is loaded there is no submission so submit is not defined and form displays without error messages
 
0
 

Author Comment

by:mts9
ID: 10889276
Points for both...thanks
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 10889303
glad i could help


thanks for the points!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
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