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

string value of radbombobox javascript

6 Answers 148 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Terje Sondresen
Top achievements
Rank 1
Terje Sondresen asked on 23 Mar 2012, 09:03 AM
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,

 

 


6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Mar 2012, 09:50 AM
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.
0
Terje Sondresen
Top achievements
Rank 1
answered on 26 Mar 2012, 08:22 AM

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

0
Princy
Top achievements
Rank 2
answered on 26 Mar 2012, 09:13 AM
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.
0
Terje Sondresen
Top achievements
Rank 1
answered on 26 Mar 2012, 09:33 AM
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 ?
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Mar 2012, 10:27 AM
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.
0
Terje Sondresen
Top achievements
Rank 1
answered on 26 Mar 2012, 10:40 AM
That worked brilliantly. thanks
Tags
ComboBox
Asked by
Terje Sondresen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Terje Sondresen
Top achievements
Rank 1
Share this question
or