Solved

Iframe not reloading on page refresh

Posted on 2010-09-09
8
628 Views
Last Modified: 2012-05-10
I have an issue with my iframe. The way it functions is this:

When the select item is changed, the value of that select field is sent to the iframe and then specific information is displayed within the iframe. This works perfectly (thanks to leakim971).

The problem is when the page is refreshed (for whatever reason) the iframe doesn't recognize the value of selectedUserID and the iframe disappears. So the user is left w/ their dropdown (w/ their previous selection still in place) and no iframe. The function only works onChange of the select.

Any suggestions?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Scientific Stature Database</title>
<cfoutput>
<link href="#request.HomeDir#blocks/styles.css" rel="stylesheet" type="text/css" />

<script>
function showUser() {
var foodd = document.getElementById("selectedUserID");
var foovalue = foodd.options[foodd.selectedIndex].value;
//	if(!foovalue) return;
var myframe = document.getElementById("myiframe");
if(foovalue.length>0) {
myframe.src = "dsp_userForm.cfm?selectedUserID="+foovalue;
myframe.style.display = "block";
myframe.setAttribute("scrolling", "auto");
}
else { 
myframe.style.display = "none";
myframe.setAttribute("scrolling", "no");
}
}


</script>


</head>
<body>
<div id="wrapper">
<div id="banner"></div>
<div id="contentWrapper" style="min-height: 500px;">

<h3>User Administration</h3>
<select id="selectedUserID" onChange="showUser()">
<option value="">Please Select</option>
  <cfloop query="session.qry_getUsers">
  <option value="#id#" <cfif selectedUserID eq id>selected</cfif>>#displayName#</option>
  </cfloop>
</select>
<br />
<br />


<iframe id="myiframe" allowtransparency="yes" align="middle" width="75%" height="500px" marginwidth="0" marginheight="0" frameborder="no">
</iframe>
<cfinclude template="../blocks/dsp_footer.cfm">
</cfoutput>
</div>
</body>
</html>

Open in new window

0
Comment
Question by:traport
  • 4
  • 4
8 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33643432
With a refresh I think you lost the selectedUserID.

In the iframe (dsp_userForm.cfm) you may retrieve directly the value selectedUserID each time you need it :


var s = parent.document.getElementById("selectedUserID");
var selectedUserID = s.options[s.selectedIndex].value;

Open in new window

0
 

Author Comment

by:traport
ID: 33645751
Hello again!

I tried placing this

<script>
var s = parent.document.getElementById("selectedUserID");
var selectedUserID = s.options[s.selectedIndex].value;
</script>

in the header of the dsp_userForm.cfm and on refresh it's not picking it up. Is that what you meant for me to try?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33645770
>in the header of the dsp_userForm.cfm and on refresh it's not picking it up.
fine, you may add an alert too debug :
var s = parent.document.getElementById("selectedUserID");
var selectedUserID = s.options[s.selectedIndex].value;
alert(selectedUserID)

>Is that what you meant for me to try?
yes

Only the iframe is refreshed ? Not the parent window ?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:traport
ID: 33645810
When a user has already selected from the select menu the drives the function and then clicks F5 or refresh, the iframe goes blank (and no alert is picking up the selectedUserID). I feel like it's because this function is only called on an "onChange" of the select and refreshing it doesn't change the select so doesn't call the function. Does that make any sense? It's as though I need to call the function on refresh as well - is that do-able?




<select name="newUserRoleID" onChange="showHide(this.value)">
<cfloop query="qry_getRoles">
<option value="#userRoleID#" <cfif userRoleID eq CurrentUserRole>selected</cfif>>#qry_getRoles.userRole#</option>
</cfloop>
</select>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33645837
>Does that make any sense? It's as though I need to call the function on refresh as well - is that do-able?

Yes it is.

Just change the iframe with the onload attribute of the parent body :

 
<body onload="showUser();"...
...
<iframe...

Open in new window

0
 

Author Closing Comment

by:traport
ID: 33646177
I feel like I owe you a cut of my paycheck for all your help. Many thanks.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33646218
I send you my IBAN immediately!!! xlol

You're very welcome! Thanks your very much for the points! Have a nice week-end!
0
 

Author Comment

by:traport
ID: 33646235
LOL! You'll be disappointed in how paltry even a large cut of my paycheck would be! :) You have a good weekend, too. Many thanks.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Load data upon clicking a button 8 35
Head to not include on scroll 4 23
I have a few questions about using the Google Developer's Console. 4 41
Javascript 2 24
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 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