Link to home
Start Free TrialLog in
Avatar of Shawn
ShawnFlag for Canada

asked on

cfdiv not regonising variables

I am using cfdiv to update a query and a menu every time a radio button is changed.

problem is I'm a little lost. I am getting the error that the variable is undefined.

In the main page I have
the script:
<script type="text/javascript">
updateStatus = function()  {
  ColdFusion.navigate('members/InternalTemplates.cfm','ITemplates');
}
</script>
the cfdiv:
<cfdiv id="ITemplates" bind="url:members/InternalTemplates.cfm"></cfdiv>

and below it the radio button:
      <input type="radio" name="TemplateLanguage" id="TemplateLanguage" value="2" onClick="updateStatus();"
               <cfif getActiveTranslation.ClientLanguage eq 2>checked</cfif>>
              French
      <input type="radio" name="TemplateLanguage" id="TemplateLanguage" value="1" onClick="updateStatus();"
        <cfif getActiveTranslation.ClientLanguage eq 1>checked</cfif>>
              English

what am I mixing up?
InternalTemplates.cfm
 
      <cfif not IsDefined("session.memberID")>
        <cflocation url="#script_name#?action=members.login2" addtoken="No">
      </cfif>
 
<cfif getActiveTranslation.ClientLanguage eq 2>
<cfset TemplateLanguage = 2>
<cfelse>
<cfset TemplateLanguage = 1>
</cfif>
 
 
<cfif TemplateLanguage eq 2>
<cfquery name="getEmails" datasource="#application.DSHome#" username="#application.dbuserHome#" password="#application.dbpassHome#">
SELECT EmailTemplateID
      ,TemplateTitle
      ,EmailSubjectFrench AS EmailSubject
      ,EmailBodyFrench AS EmailBody
  FROM tblEmailTemplate
</cfquery>
<cfelse>
<cfquery name="getEmails" datasource="#application.DSHome#" username="#application.dbuserHome#" password="#application.dbpassHome#">
SELECT EmailTemplateID
      ,TemplateTitle
      ,EmailSubject
      ,EmailBody
  FROM tblEmailTemplate
</cfquery>
</cfif>
 
<script type="text/javascript">
// this is a js array of objects from the query data
var arrTemplates = [<cfoutput query="getEmails">
					{'etid':#EmailTemplateID#, 'subj':'#jsstringformat(EmailSubject)#', 'body':'#jsstringformat(EmailBody)#'}
					<cfif getEmails.currentrow LT getEmails.recordcount>,</cfif></cfoutput>];
 
// this function is executed in onchange() event of the select drop-down and populates the 2 form fields with data from the above js array
var showTemplate = function(id) {
  if (id > 0) {
    for (var x=0; x<arrTemplates.length; x++) {
      if (arrTemplates[x].etid == id) {
        document.getElementById('Subject').value = arrTemplates[x].subj;
        document.getElementById('fEmailBody').value = arrTemplates[x].body;
      }
    }
  }
};
</script>
 
 
<div class="TemplateMenu">
<ul>
<li><a href="">Templates</a>
<!--[if lte IE 6]>
<a href="../menu/index.html">Templates
<table><tr><td>
<![endif]-->
	<ul>
    <cfoutput query = "getEmails">
        <cfif getEmails.RecordCount IS not 0>
        <li><a class="hide"  title="choose this template" href="##" onclick="showTemplate(#EmailTemplateID#); return false;">#TemplateTitle#</a>
        <!--[if lte IE 6]>
    	<a class="sub" href="#EmailTemplateID#" title="choose this template">#TemplateTitle#
    	<table><tr><td>
    	<![endif]-->
        
        	<ul>
				<li><a href="##" onclick="showTemplate(#EmailTemplateID#); return false;" title="choose this template">#EmailSubject#<br>***<br>#EmailBody#</a></li>
			</ul>
		<!--[if lte IE 6]>
		</td></tr></table>
    	</a>
    	<![endif]-->
		
        </li>
        <cfelse>
        <li><a href="">*** no templates ***</a></</li>
        </cfif>        
    	</cfoutput>
</ul>	
<!--[if lte IE 6]>
</td></tr></table>
</a>
<![endif]-->
</li>
</ul>
</div>

Open in new window

Avatar of Shawn
Shawn
Flag of Canada image

ASKER

the problem seems to be I am unable to pass variables from the main page to the included page in cfdiv.
how can I do this?
read the docs about ColdFusion.navigate() function - it accepts a form id as an optional parameter, which will submit that form to designated url.

so your updateStatus function should look like this:

updateStatus = function()  {
  ColdFusion.navigate('members/InternalTemplates.cfm','ITemplates',null,null,'POST','id-of-your-form-here');
}


now, in your InternalTemplates.cfm you will need to reference FORM variables instead of non-existent queries:

<cfif not IsDefined("session.memberID")>
  <cflocation url="#script_name#?action=members.login2" addtoken="No">
</cfif>
 
<cfparam name="FORM.TemplateLanguage" default="1">

<cfif FORM.TemplateLanguage eq 2>
  <cfquery name="getEmails" datasource="#application.DSHome#" username="#application.dbuserHome#" password="#application.dbpassHome#">
  SELECT EmailTemplateID
      ,TemplateTitle
      ,EmailSubjectFrench AS EmailSubject
      ,EmailBodyFrench AS EmailBody
  FROM tblEmailTemplate
  </cfquery>
<cfelse>
  <cfquery name="getEmails" datasource="#application.DSHome#" username="#application.dbuserHome#" password="#application.dbpassHome#">
  SELECT EmailTemplateID
      ,TemplateTitle
      ,EmailSubject
      ,EmailBody
  FROM tblEmailTemplate
  </cfquery>
</cfif>
... rest of your code...

Azadi
Avatar of Shawn

ASKER

updateStatus = function()  {
  ColdFusion.navigate('members/InternalTemplates.cfm','ITemplates',null,null,'POST','id-of-your-form-here');
}
not sure I get it. at this stage I don't want to submit the form, I just want to update the info on the page. Am I missing something?
Avatar of Shawn

ASKER

ok, should have tried it out before my last comment. It seems to load fine but the the script below my query doesn't work anymore??
Avatar of Shawn

ASKER

looks like the script should be on main page but then the variables throw th undefined erro
i don;t know how hat script is supposed to work, so i can't really tell you why it's not working...
i know it is based on the code i gave you in your other question, but you seem to have added quiet a bit to it...

the only thing that jumps out at me is that my original js code populated 2 form fields with data from js array - but i do not see any form fields in your code... where are they? in the main page?

try moving just the updateStatus() function to the main page. obviously you need to keep the code that generates the js array in your InternalTemplates.cfm file as it uses the query which is in that page.

Azadi
sorry, i meant try moving the showTemplate() function, not updateStatus() ... copied from a wrong place...

Azadi
Avatar of Shawn

ASKER

the only thing that jumps out at me is that my original js code populated 2 form fields with data from js array - but i do not see any form fields in your code... where are they? in the main page?

yes, they're in the main page. I tried to split up the code so the array could be updated with the radio button change.

I split up the js code but it still doesn't populate the 2 fields (in the main form)...on main page I have
<script type="text/javascript">

// this function is executed in onchange() event of the select drop-down and populates the 2 form fields with data from the above js array
var showTemplate = function(id) {
  if (id > 0) {
    for (var x=0; x<arrTemplates.length; x++) {
      if (arrTemplates[x].etid == id) {
        document.getElementById('Subject').value = arrTemplates[x].subj;
        document.getElementById('fEmailBody').value = arrTemplates[x].body;
      }
    }
  }
};
</script>

in the InternalTemplates.cfm I have:
<script type="text/javascript">
// this is a js array of objects from the query data
var arrTemplates = [<cfoutput query="getEmails">
                              {'etid':#EmailTemplateID#, 'subj':'#jsstringformat(EmailSubject)#', 'body':'#jsstringformat(EmailBody)#'}
                              <cfif getEmails.currentrow LT getEmails.recordcount>,</cfif></cfoutput>];
</script>
ok, figured it out - small provlem with js variables declarations.

here's what you need to do:

1) this is the javascript to go into your main page:
<script type="text/javascript">
var arrTemplates; // this line declares a variable which will be you array later
var showTemplate = function(id) {
  if (id > 0) {
    for (var x=0; x<arrTemplates.length; x++) {
      if (arrTemplates[x].etid == id) {
        document.getElementById('Subject').value = arrTemplates[x].subj;
        document.getElementById('fEmailBody').value = arrTemplates[x].body;
      }
    }
  }
};
</script>

2) in the javascript in your InternalTemplates.cfm file remove the word VAR from in front of arrTemplates


Azadi
Avatar of Shawn

ASKER

ok that worked. thank you!

only one loose end. in the InternalTemplates.cfm we have:
<cfparam name="FORM.TemplateLanguage" default="1">

I need to find a way to pass a variable from the main page to this page. in the main page there is another query which gives the TemplateLanguage a value.
getActiveTranslation.ClientLanguage

how do I link the 2? or is this another question?:-)
Avatar of Shawn

ASKER

the query in the main page is below in case it helps
<cfquery name="getActiveTranslation" datasource="#application.DSHome#" username="#application.dbuserHome#" password="#application.dbpassHome#">
SELECT q.trad_commandesID, q.status, q.no_commande as JobNumber, q.delai_gen, InternalComments, EmailAbsolute, CC, 
delai_heure, CodeClientTraductions, Prenom, Nom, Societe, ClientLanguageNew, ClientLanguage, HostCompanyID, HostCompanyName
FROM  ARAXICONTACTS...sql_ActiveTranslationOrders AS q
WHERE q.trad_commandesID = <cfqueryparam cfsqltype="cf_sql_integer" value="#TranslationID#">
</cfquery>

Open in new window

you used to have 2 radio buttons on your main page that were used to select a language... do you still have them?
the value of selected radio button is passed to the InternalTemplates.cfm page using ColdFusion.navigate() function - that's why you specify the form id in it: to submit the form with radio buttons to your InternalTemplates.cfm page so the selected language value can be available in that page. make sure you specify ID of correct form in ColdFusion.navigate() fucntion.

just to make sure you understand correctly:
the 'id-of-your-form-here' text in ColdFusion.navigate() function code in my first answer is supposed to be replaced with the id of your form that has the radio buttons.

Azadi
Avatar of Shawn

ASKER

yes, I still have them:
      <input type="radio" name="TemplateLanguage" id="TemplateLanguage" value="2" onClick="updateStatus();"
               <cfif getActiveTranslation.ClientLanguage eq 2>checked</cfif>>
              French
      <input type="radio" name="TemplateLanguage" id="TemplateLanguage" value="1" onClick="updateStatus();"
        <cfif getActiveTranslation.ClientLanguage eq 1>checked</cfif>>
              English

my form id is:
 <FORM  id="MemberEmails"action=index.cfm?action=members.TOrders-a method=post enctype="multipart/form-data" name="form">
so that shold be ok

must be something wrong in my radion buttons then?
Avatar of Shawn

ASKER

sorry, should have explained better.
when I change the value of the radio button it works. it is when the page is originally loaded that the variable is not passed.
ASKER CERTIFIED SOLUTION
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

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 Shawn

ASKER

:-D did it again. very nice logic.
thank you, Shawn