Clientside event for a combobox

3 posts, 0 answers
  1. sravanthi
    sravanthi avatar
    23 posts
    Member since:
    Aug 2010

    Posted 14 Sep 2011 Link to this post

    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. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 16 Sep 2011 Link to this post

    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
  3. sravanthi
    sravanthi avatar
    23 posts
    Member since:
    Aug 2010

    Posted 16 Sep 2011 Link to this post

    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
Back to Top