This is a migrated thread and some comments may be shown as answers.

Replace NavigateUrl with javascript function

2 Answers 133 Views
TagCloud
This is a migrated thread and some comments may be shown as answers.
Yeroon
Top achievements
Rank 2
Yeroon asked on 30 Jul 2010, 11:41 AM
Hello,

I build a tagcloud based on the content of a certain text. Everything works great. Gratulations on yet another fine RadControl.

I was wondering however if it would be possible to have the click on a tag trigger a clientside javascript function. Through the click I want to call my highlighting script, which obviously would highlight the clicked tag text in my body  text.

Is there any way to achieve this functionality (the javascript function call from a tag).

With regards,

Jeroen

2 Answers, 1 is accepted

Sort by
0
Accepted
Pero
Telerik team
answered on 30 Jul 2010, 04:44 PM
Hello Jeroen,

I believe the easiest way would be to handle the OnClientItemClicking client-side event, and then get the tagCloud item clicked as shown in the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function OnClientItemClicking(tagCloud, args)
        {
            var currentItem = args.get_item();
            alert("Text: " + currentItem.get_text() + " NavigateUrl: " + currentItem.get_navigateUrl());
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    <telerik:RadTagCloud ID="TagCloud1" runat="server" Width="400px" OnClientItemClicking="OnClientItemClicking">
        <Items>
            <telerik:RadTagCloudItem Text="ASP.NET" Weight="12" />
            <telerik:RadTagCloudItem Text="AJAX" Weight="134" />
            <telerik:RadTagCloudItem Text="VB" Weight="56" />
            <telerik:RadTagCloudItem Text="C#" Weight="38" />
            <telerik:RadTagCloudItem Text="Web" Weight="73" />
            <telerik:RadTagCloudItem Text="jQuery" Weight="23" />
            <telerik:RadTagCloudItem Text=".NET" Weight="78" />
            <telerik:RadTagCloudItem Text="Code" Weight="50" />
            <telerik:RadTagCloudItem Text="UI" Weight="80" />
            <telerik:RadTagCloudItem Text="Unit" Weight="20" />
            <telerik:RadTagCloudItem Text="Class" Weight="50" />
            <telerik:RadTagCloudItem Text="Tools" Weight="40" />
            <telerik:RadTagCloudItem Text="Dynamic" Weight="58" />
            <telerik:RadTagCloudItem Text="Telerik" Weight="60" />
            <telerik:RadTagCloudItem Text="HTTP" Weight="64" />
            <telerik:RadTagCloudItem Text="Start" Weight="62" />
            <telerik:RadTagCloudItem Text="Response" Weight="23.7" />
            <telerik:RadTagCloudItem Text="Client-side" Weight="55" />
            <telerik:RadTagCloudItem Text="Default" Weight="8.5" />
            <telerik:RadTagCloudItem Text="Event" Weight="45" />
            <telerik:RadTagCloudItem Text="Property" Weight="24" />
            <telerik:RadTagCloudItem Text="Tests" Weight="81" />
            <telerik:RadTagCloudItem Text="Method" Weight="87" />
            <telerik:RadTagCloudItem Text="DataSource" Weight="34" />
            <telerik:RadTagCloudItem Text="JavaScript" Weight="35.70" />
            <telerik:RadTagCloudItem Text="Server-side" Weight="59.3" />
            <telerik:RadTagCloudItem Text="Accessibility" Weight="15.7" />
            <telerik:RadTagCloudItem Text="HTML5" Weight="90" />
            <telerik:RadTagCloudItem Text="XHTML" Weight="47.8" />
            <telerik:RadTagCloudItem Text="Compliance" Weight="29.45" />
            <telerik:RadTagCloudItem Text="Callback" Weight="53" />
            <telerik:RadTagCloudItem Text="Request" Weight="39.3" />
            <telerik:RadTagCloudItem Text="Postback" Weight="9.5" />
            <telerik:RadTagCloudItem Text="DOM" Weight="65.49" />
            <telerik:RadTagCloudItem Text="Markup" Weight="35.49" />
            <telerik:RadTagCloudItem Text="Trigger" Weight="24.975" />
            <telerik:RadTagCloudItem Text="XML" Weight="43.975" />
            <telerik:RadTagCloudItem Text="CSS" Weight="14.392" />
            <telerik:RadTagCloudItem Text="Object" Weight="85.6" />
        </Items>
    </telerik:RadTagCloud>
    </form>
</body>
</html>


All the best,
Pero
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yeroon
Top achievements
Rank 2
answered on 31 Jul 2010, 04:03 PM
Great :) Works like a charm!
Tags
TagCloud
Asked by
Yeroon
Top achievements
Rank 2
Answers by
Pero
Telerik team
Yeroon
Top achievements
Rank 2
Share this question
or