Copy link to clipboard
Copied
Hallo everybody. Mein name is Cristiano and I've got a problem.
I'm trying to change the language of my Homepage when I click on an small flag on the right corner. Something that everyone has already seen in the Internet. Very simple.
To hold the language I created a session variable, that should change his value, when I click on the picture.
I have written the following function, that functions perfectly.
<cffunction name="changeLanguage">
<cfargument name="language" type="string">
<cfset session.userLanguage = language>
<cfreturn session.userLanguage>
</cffunction>
But my problem is when I click on the image nothing happens.
<img src="images/de.gif" width="19" height="15" onclick="changeLanguage('DE')"/>
<img src="images/fr.gif" width="19" height="15" onclick="changeLanguage('FR')"/>
DE = german
FR = france
What is wrong with my code? Can I do that with onclick or there is a better way?
It's possible to mix JavaScript and ColdFusion without a problem?
Thank you for your help
Cristiano
Copy link to clipboard
Copied
The basic problem is that an onClick event for a web page element either calls a javascript function which runs on the client. Your coldfusion function runs on the server.
Depending on the complexity of the page, the best method might be a page request.
Copy link to clipboard
Copied
And will it work if I wirte a Java-Script function?
Thank you for your answer.
Cristiano
Copy link to clipboard
Copied
If you try hard enough you can get anything to work.
To use just javascript, you have to pass the entire contents of your page, in all available languages to javascript so that it's available on the client. That may or may not be feasible, depending on the complexity of the page.
If you are on CF 8 or 9, you have access to ajax, which uses javascript to connect back to the cold fusion server where you can do what you need to do.
Copy link to clipboard
Copied
Dan Bracuk wrote:
If you are on CF 8 or 9, you have access to ajax, which uses javascript to connect back to the cold fusion server where you can do what you need to do.
To be technical you have access to ajax with ColdFusion 6 and 7 with community support projects, and I presume nothing prevents one from creating some ajax functionality in older version as well. You just don't have the nice built in functionality that comes with 8 and 9 that make ajax pretty darn simple.