Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Change language with onclick-event?

Guest
Jan 05, 2010 Jan 05, 2010

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

TOPICS
Getting started
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 05, 2010 Jan 05, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 05, 2010 Jan 05, 2010

And will it work if I wirte a Java-Script function?

Thank you for your answer.

Cristiano

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 05, 2010 Jan 05, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 05, 2010 Jan 05, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources