Skip to main content
Inspiring
Jan 31, 2012 4:45 PM UTC
Answered

execute js function on clicking tab?

i have a js function that works fine when attached to the onClick event of a button, but i want it to execute when user clicks the tab

is there a way to do that?

function clearURL() {

var testURL = document.URL;

var urlQry = testURL.split("?")[1];

if (urlQry != "")

    {

    var activeTab = ColdFusion.Layout.getTabLayout('myLayout').getActiveTab().title;

    if (activeTab == 'myTabTitle')

        {

        var newURL = testURL.split("?")[0];

        window.location = newURL;

        }

    }

}

thanks

This topic is closed to new replies. Start a new post to keep the conversation going.
ionCorrect answer
Inspiring
Jun 12, 2014 6:09 PM UTC

Thanks again AnotherPGriff, you pointed me in the right direction. My working code is:

ColdFusion.Layout.onTabActivate = function(tab){

  myTabs = ColdFusion.Layout.getTabLayout("myLayout");

  actTab = myTabs.getActiveTab();

  if(actTab.id === "myRedirect") {

  ColdFusion.navigate("redirectFile.cfm");

  }

}

where actTab.id is actually the name attribute of my cflayoutarea

Regards

8 replies

Legend
Jun 22, 2012 12:30 AM UTC

Maybe this will help: http://api.jquery.com/keypress/

Translate
ionAuthorCorrect answer
Inspiring
Jun 12, 2014 6:09 PM UTC

Thanks again AnotherPGriff, you pointed me in the right direction. My working code is:

ColdFusion.Layout.onTabActivate = function(tab){

  myTabs = ColdFusion.Layout.getTabLayout("myLayout");

  actTab = myTabs.getActiveTab();

  if(actTab.id === "myRedirect") {

  ColdFusion.navigate("redirectFile.cfm");

  }

}

where actTab.id is actually the name attribute of my cflayoutarea

Regards

Translate
BKBK
Community Expert
Community Expert
Jan 31, 2012 7:37 PM UTC

<div onclick="clearURL()">

<cflayout>

</cflayout>

</div>

Translate
ionAuthor
Inspiring
Jan 31, 2012 11:28 PM UTC

thanks BKBK, but is not really working. is not the whole layout that needs to be affected, only one layoutarea.

when i do this, it throws the layout out of wack, and when clicked, it does nothing (no error either)

regards

Translate
BKBK
Community Expert
Community Expert
Feb 1, 2012 8:23 PM UTC

ion wrote:

thanks BKBK, but is not really working. is not the whole layout that needs to be affected, only one layoutarea.

when i do this, it throws the layout out of wack, and when clicked, it does nothing (no error either)

I understand. You could place the DIV within the layoutarea, as in this example:

<script type="text/javascript">

f = function () {

    alert('Karamba!')

}

</script>

<cflayout type="tab" name="tabLayout">

    <cflayoutarea name="tab1" title="Tab 1">

       Tab 1 contents

    </cflayoutarea>

     <cflayoutarea name="tab2" title="Tab 2">

           <div  onclick="f()" >

       Tab 2 contents

    </div>

    </cflayoutarea>     

</cflayout>

Translate