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

Clientside event for a combobox

2 Answers 30 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
sravanthi
Top achievements
Rank 1
sravanthi asked on 14 Sep 2011, 02:27 PM
Hi Every one,

this is what I am doing on client side

<telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function OnClientSelectedIndexChanged_Country(sender, eventArgs) {
                var item = eventArgs.get_item();
                var inputElement = document.getElementById("<%= rpbMainInfo.FindItemByValue("CandidateInformation").FindControl("rtxtState").ClientID %>"); 
                 
                var Combo = document.getElementById("<%= rpbMainInfo.FindItemByValue("CandidateInformation").FindControl("rcbState").ClientID %>");
                if (item.get_selectedItem() == "United States") {
                    Combo.set_visible = true;
                    inputElement.set_visible = false;
                }
                else {
                    Combo.set_visible = false;
                    inputElement.set_visible = true;
                }
            }        
        </script>
    </telerik:RadCodeBlock>


<telerik:RadComboBox ID="rcbCountry" runat="server" DataSourceID="sdsCountries" DataTextField="COUNTRY"
                                                        DataValueField="COUNTRYCODE" Skin="Outlook" EmptyMessage="Please Select.."
                                                         OnClientSelectedIndexChanged="OnClientSelectedIndexChanged_Country">
                                                    </telerik:RadComboBox>


What I am trying to do is when the user selects the country as Unitedstates the combo box for states should be visible and when Country other than United states then the states would be a text box.I am able to do this on server side .But I am not able to get on client side .....

CAn we do it on client side or only sever side.




Can Any one help me with this please.


Thanks,
Sravanthi

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Sep 2011, 12:01 PM
Hello,

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
       
      <script type="text/javascript">
 
          function onSelectedIndexChanged(sender, eventArgs) {
              var RadComboBox2 = $find("<%= RadComboBox2.ClientID %>");
              var RadTextBox1 = $find("<%= RadTextBox1.ClientID %>");
              var TextBoxContainer = document.getElementById('<%=TextBoxContainer.ClientID %>');
 
              var selectedItem = eventArgs.get_item();
              var selectedItemvalue = selectedItem != null ? selectedItem.get_value() : sender.get_value();
 
              if (selectedItemvalue == "1") {
                  RadComboBox2.set_visible(true);
                  RadTextBox1.set_visible(false);
                  TextBoxContainer.style.display = "none";
              }
              else {
                  RadComboBox2.set_visible(false);
                  RadTextBox1.set_visible(true);
                  TextBoxContainer.style.display = "";
              }
 
          }
      </script>
  </telerik:RadCodeBlock>
<telerik:RadComboBox OnClientSelectedIndexChanged="onSelectedIndexChanged" ID="RadComboBox1"
           runat="server">
           <Items>
               <telerik:RadComboBoxItem Text="US" Value="1" />
               <telerik:RadComboBoxItem Text="None" Value="2" />
           </Items>
       </telerik:RadComboBox>
       <telerik:RadComboBox ID="RadComboBox2" runat="server">
       </telerik:RadComboBox>
       <div id="TextBoxContainer" runat="server" style="display: none;">
           <telerik:RadTextBox ID="RadTextBox1" runat="server">
           </telerik:RadTextBox>
       </div>


Thanks,
Jayesh Goyani
0
sravanthi
Top achievements
Rank 1
answered on 16 Sep 2011, 08:04 PM
HI Jayesh,
My elements are in a telerik:RadPanelItem so to identify each element I need to write it like this

var Combo = document.getElementById("<%= rpbMainInfo.FindItemByValue("CandidateInformation").FindControl("rcbState").ClientID %>");

I dont know y its not working.

Thanks,
Sravanthi
Tags
ComboBox
Asked by
sravanthi
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
sravanthi
Top achievements
Rank 1
Share this question
or