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

Set Variable onClick

Community Beginner ,
Apr 05, 2012 Apr 05, 2012

I want to set a varaible on a button click.  I have been trying this:

<a href="##" onclick="document.getElementById('faq1').style.display='block';    

                                 document.getElementById('faq2').style.display='none';    

                                 document.getElementById('faq3').style.display='none';

                                <cfset pageCount = pageCount + 1>">

<span class="contentHeader">Overview</span>

</a>

This does not seem to work.  Does anyone have any ideas how to make this work?  Thanks

2.7K
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 ,
Apr 05, 2012 Apr 05, 2012

It's not clear what you are attempting.  The only variable I see is pageCount but I don't see anywhere where you are attempting to display it.

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
Community Beginner ,
Apr 06, 2012 Apr 06, 2012

I am not trying to display it.  I am keeping track of it and once it reaches three a button appears on the screen.

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
Participant ,
Apr 06, 2012 Apr 06, 2012

You are trying to set a ColdFusion (server side) variable using Javascript (client side).  You cannot run ColdFusion code in the browser.  If you look at the source, you will see that your <cfset ... /> is not passed along to the browser.

You could call an ajax request which would execute CF code on the server to increase the count and store it in the user's session, for example, but I think you need to go back to the basics and understand the difference between client side code and server side.

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
Community Expert ,
Apr 07, 2012 Apr 07, 2012
LATEST

TheScarecrow wrote:

I want to set a varaible on a button click.  I have been trying this:

<a href="##" onclick="document.getElementById('faq1').style.display='block';    

                                 document.getElementById('faq2').style.display='none';    

                                 document.getElementById('faq3').style.display='none';

                                <cfset pageCount = pageCount + 1>">

<span class="contentHeader">Overview</span>

</a>

This does not seem to work.  Does anyone have any ideas how to make this work?  Thanks

I see no button. I see no variable that needs setting either. Could you explain a bit more?

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