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

Javascipt

2 Answers 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 2
Brad asked on 30 Mar 2009, 05:42 AM
I've been programming for quite a few years so an if statement shouldn't be THAT difficult.
Coming from a RadPanelBar
Here's the code: 
   function OnClicked(sender, eventArgs) {
       if (true) 
           alert(eventArgs.get_item().get_text());
        LogEvent("On clicked: " + eventArgs.get_item().get_text());
   }
The above works. No problems. The alert give me "WOR" which is what I'd expect and then in a text field (Logged set inside the LogEvent function) I get "On clicked: WOR". Now I try this:

    function OnClicked(sender, eventArgs) {
        if (eventArgs.get_item().get_text() = "WOR") 
            alert(eventArgs.get_item().get_text());
        LogEvent("On clicked: " + eventArgs.get_item().get_text());
    }
I get NOTHING! No alert window. The Logged text field shows nothing. I am really confused (and seriously annoyed). WHAT is wrong with this construct? I have serious SQL running behind RadCharts in RadWindows which I want to open when a user clicks on an item in a panel bar. And this SIMPLE if statement is holding me up.
HELP!!!!

TIA,

Joe B



2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Mar 2009, 06:15 AM

Hi Joe,

I tried the scenario and found that its working for me. Please make sure that you used the correct syntax for if statement.
Note: When comparing variables you must always use two equals signs next to each other (==)!

Here is my code,
ASPX:

<telerik:radpanelbar id="RadPanelBar1" runat="server" OnClientItemClicked="OnClicked" > 
<Items> 
    <telerik:RadPanelItem Text="WOR"></telerik:RadPanelItem> 
    <telerik:RadPanelItem Text="Item2"></telerik:RadPanelItem>          
</Items> 
</telerik:radpanelbar> 

JavaScript:

<script type="text/javascript">  
function OnClicked(sender, eventArgs)  
{  
      if (eventArgs.get_item().get_text() == "WOR")  
           alert(eventArgs.get_item().get_text());  
}  
</script> 

Thanks,
Princy.
0
Brad
Top achievements
Rank 2
answered on 30 Mar 2009, 06:34 PM
Princy,

The double equals was the solution. Too much SQL coding habits I guess. Thanks for the answer.

Joe B
Tags
General Discussions
Asked by
Brad
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Brad
Top achievements
Rank 2
Share this question
or