string value of radbombobox javascript

7 posts, 1 answers
  1. Terje Sondresen
    Terje Sondresen avatar
    6 posts
    Member since:
    Mar 2009

    Posted 23 Mar 2012 Link to this post

    Hi,

    im trying to extract the value of a radcombobox. Previously this value was stored in a regular asp textbox, then I could do like this to get the last part of the string value in js.

    Right(document.getElementById('Mybox').value, 5) < 1000

    this number is built up like so. 'project-module-1xxx'

    I.E I only want to get values that are higher than 1000. How can I get the same functionality from a radcombobox ?

    I tried with

    Right($find("Mybox").get_text(), 5) < 1000) but that didnt recognize the right functionality.

    all help appreciated,

     

     


  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Mar 2012 Link to this post

    Hello,

    When you are trying to access RadControls the correct method is to use $find instead of document.getElementByID as follows.
    JS:
    var txtID = $find("<%= Mybox.ClientID %>");

    Thanks,
    Princy.
  3. Terje Sondresen
    Terje Sondresen avatar
    6 posts
    Member since:
    Mar 2009

    Posted 26 Mar 2012 Link to this post

    Hi,

    this would then be the solution


    var
    txtID = $find("MyBox");

    if (Right(txtID.value, 5) < 1000) {
    // do some updates here
    }

    That does not work im afraid, you get a Error: The value of the property 'Right' is null or undefined, not a Function object

  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Mar 2012 Link to this post

    Hello,

    Try the following approach to get the value from RadComboBox.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
     <Items>
      <telerik:RadComboBoxItem Text="RadComboBoxItem1" Value="1" />
      <telerik:RadComboBoxItem Text="RadComboBoxItem2" Value="2"/>
      <telerik:RadComboBoxItem Text="RadComboBoxItem3" Value="3" />
      <telerik:RadComboBoxItem Text="RadComboBoxItem4" Value="4"/>
      <telerik:RadComboBoxItem Text="RadComboBoxItem5" Value="5"/>
      <telerik:RadComboBoxItem Text="RadComboBoxItem6" Value="5"/>
     </Items>
    </telerik:RadComboBox>

    JS:
    <script type="text/javascript">
    function OnClientSelectedIndexChanged(sender, args)
     {
      var txtID = $find("<%= RadComboBox1.ClientID %>");
      alert(txtID._value);
     }
    </script>

    Thanks,
    Princy.
  5. Terje Sondresen
    Terje Sondresen avatar
    6 posts
    Member since:
    Mar 2009

    Posted 26 Mar 2012 Link to this post

    Hi,

    thats not really what I asked.

    I have no problem getting the value from the radcombobox, I have a problem extracting a part of it to JS.
    if it was an asp control. this is what i would do. This will extract the last 5 numbers from the string

    Right(document.getElementById('Mybox').value, 5) < 1000

    now if mybox was a radcombobox instead, then how would I write that above code ?
  6. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Mar 2012 Link to this post

    Hello,

    I tried the following approach to extract the last 5 numbers from the text in the RadCOmboBox and it is working for me.
    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server">
    <Items>
    <telerik:RadComboBoxItem Text="100000" Value="1" />
    <telerik:RadComboBoxItem Text="10004" Value="2"/>
    <telerik:RadComboBoxItem Text="100010000" Value="3" />
    <telerik:RadComboBoxItem Text="111101000" Value="4"/>
    <telerik:RadComboBoxItem Text="125555" Value="5"/>
    <telerik:RadComboBoxItem Text="12222" Value="5"/>
    </Items>
    </telerik:RadComboBox>
    <asp:Button ID="Button1" runat="server" OnClientClick="OnClientClick(); return false;" />

    JS:
    <script type="text/javascript">
     function OnClientClick()
      {
       var txtID = $find("<%= RadComboBox1.ClientID %>");
       alert(Right(txtID.get_text(), 5));
       if (Right(txtID.get_text(), 5) > 1000)
        {
         alert("Inside if");
        }
      }
     function Right(str, n)
      {
       if (n <= 0)
        return "";
       else if (n > String(str).length)
        return str;
       else
        {
         var iLen = String(str).length;
         return String(str).substring(iLen, iLen - n);
        }
      }
    </script>

    Can you please provide your code if it is not working.

    Thanks,
    Princy.
  7. Terje Sondresen
    Terje Sondresen avatar
    6 posts
    Member since:
    Mar 2009

    Posted 26 Mar 2012 Link to this post

    That worked brilliantly. thanks
Back to Top