Link to home
Start Free TrialLog in
Avatar of mts9
mts9

asked on

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

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!
SOLUTION
Avatar of riffraff5
riffraff5

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
Avatar of James Rodgers
>>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;
}

}

}
Avatar of mts9
mts9

ASKER

All,

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

Thanks
Mike
Because you are not providing any way to maintain persistance of the user's inputs.
ASKER CERTIFIED SOLUTION
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
Avatar of mts9

ASKER

Points for both...thanks
glad i could help


thanks for the points!