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

[Solved] Getting text in Combo, *CLIENT* side

5 Answers 226 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Steve Bywaters
Top achievements
Rank 1
Steve Bywaters asked on 05 May 2008, 02:38 AM
The documentation says to use the GetText() function to get the text, once you've got the Combo object.

So I used this:
function GetComboText(id)             {           /* Get a reference to the Combo   */  
//onclick="window.radopen('Companies.aspx?Popup=1&Name=' + GetComboText(ctl00_ContentPlaceHolder1_fvJobEdit_cmbLocation), 'rwCompanyEdit'); return false;" 

    var comboBox = document.getElementById(id);  
    alert("combo id=" + comboBox.id);  
    try {  
        var T = comboBox.GetText();  
        }  
    catch(err)  {  
        alert(err);  
        }  
 
 

But the Catch block activates, with the message:
    "TypeError: comboBox.GetText is not a function"

(You will see that I *did* call GetText() with brackets, avoiding that simple error!)

However, if I use this code:
function GetComboText(id)             {           /* Get a reference to the Combo   */  
//onclick="window.radopen('Companies.aspx?Popup=1&Name=' + GetComboText(ctl00_ContentPlaceHolder1_fvJobEdit_cmbLocation), 'rwCompanyEdit'); return false;" 
 
    var inputID = id + "_Input"  
    try {  
    var comboBoxInput = document.getElementById(inputID);  
    alert("comboBoxInput=" + comboBoxInput.value);  
    }  
    catch(err)      {  
        alert("no comboBoxInput");  
        }  
 
 

Then I DO get the right value back!

But this is 'bad form' right?
Shouldn't I be using the proper function for the combo?
So why doesn't it work?

(BTW the combo is used in a callback scenario - does this make a difference?)

tia
Steve













 

5 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 05 May 2008, 07:27 AM
Hi Steve Bywaters,

The reason for the problem is the way you access RadComboBox instance.

If you use RadComboBox for ASP.NET please follow the link:
http://www.telerik.com/help/aspnet/combobox/combo_client_basics.html

if you use RadComboBox for ASP.NET AJAX read the following article.

Getting the RadComboBox client-side object

Also,notice that if you use this version GetText() method is replaced with get_text();

Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Steve Bywaters
Top achievements
Rank 1
answered on 05 May 2008, 07:47 AM
If you use RadComboBox for ASP.NET please follow the link:
if you use RadComboBox for ASP.NET AJAX read the following article.

I use:
  • Combo with callback page
  • Page is wrapped in AjaxPanel

Which of the 2 do do I qualify as ?
(Which link is relevant?)

Also, I'm sorry, but NEITHER of those articles mention GetText or get_text.
In fact  I can find no mention of get_text in any of my documentation!

ALL examples are like this (below):

Getting the client-side Telerik RadComboBox instance

You can get the client-side object instance of Telerik RadComboBox using its  ClientID, e.g. for combobox instance with ID="RadComboBox1":

<radcb:RadComboBox runat="server" ID="RadComboBox1" ... />

You can get the instance using the following JavaScript:

<script language="javascript">
    var RadComboBox1 = <%= RadComboBox1.ClientID %>;
    var comboText =
RadComboBox1.GetText();
    alert(comboText);
</script>

0
Steve Bywaters
Top achievements
Rank 1
answered on 05 May 2008, 07:50 AM
BTW my version is 2.7, (Q1 2007)

That means I am using Combo for ASP.NET, right?

Which means that I *was* using the correct function!
0
Rosi
Telerik team
answered on 05 May 2008, 08:37 AM
Hello Steve Bywaters,

Yes, you used the correct function but you did not use the correct way for getting the client side object of RadComboBox. This is the reason for the problem.

I suggest you replaced this line of your code:

var comboBox = document.getElementById(id);  

with

var comboBox = <%= id%>;

or

var comboBox = window[id];

Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Steve Bywaters
Top achievements
Rank 1
answered on 05 May 2008, 09:15 AM
ok....

    var comboBox = window[id];

is good for me.. allowing me to pass the ids of several combos into the same function.

I keep getting tripped up on the differences between using a RadWindow and my own hand-coded popup window!

GetElementByID is not good here, it seems, but window[id] works...
Thanks for the tip.

Steve
Tags
ComboBox
Asked by
Steve Bywaters
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Steve Bywaters
Top achievements
Rank 1
Share this question
or