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

[Solved] Help with Combo client code

2 Answers 220 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 27 Dec 2009, 02:08 PM
Argh...I apologize for bugging everyone at this time of the year, but I am having issues trying to retrieve the selected values from a combo box inside client javascript and am working on a demanding schedule.

I have a combo box (for example) populated as:

Item 1: Text=Sell; Value=1.
Item 2: Text=Rent; Value=2.
Item 3: Text=Trade; Value=3.

When the user selects an item from the combo (and enters text in a couple of textboxes) then clicks on an item on the screen, I need to open a new window and pass the value selected in the combo box.  I can't do this inside the server code, because a postback would end up basically performing a redirect and I need to keep the original window on the screen.

I cannot capture the combo box selected value when the user selects it, because they may just use the default value thus not triggering any events on the combo box before clicking on the screen item to continue.

I should add that I am using the combo box on a page that utilizes a master page, and that the combo box is defined inside a RadDock.

In my client javascript, I have tried several methods of doing this, but all I can seem to retrieve is the text value displayed in the combo box.  For examples:

Example 1.  The following code retrieves the actual visible text value from the combo (i.e. - trade, sell, rent)

a1 = document.getElementById("<%= ListTranType.ClientID %>").value;
alert(a1);

Example 2.  In the following, b1 displays [object object] and b2 displays undefined

var b1 = $find("<%= ListTranType.ClientID %>");
alert(b1);
var b2 = b1.value;
alert(b2);

Example 3.  The following code works exactly like #1 above. Only the visible text from the combo is displayed (sell, rent, trade).

var b1 = $find("<%= ListTranType.ClientID %>").value;
alert(b1);


The combo box is defined as shown below. 

<

 

telerik:RadComboBox ID="ListTranType" OnClientSelectedIndexChanged="gettrantype" EnableEmbeddedSkins="true" Skin="Black" runat="server" Width="200px" ></telerik:RadComboBox>

 

 I do have a script for capturing the value when the user selects one and it works fine as it is, but as said earlier sometimes the user will use the default value or not select one from the combo before clicking to proceed.  Both of these actions are valid within the application.  The code used to capture the value during the event is:

 

<script type="text/javascript">

 

 

 

var trantype;

 

 

function gettrantype(combo, eventArqs) {

 

 

var item = eventArqs.get_item();

 

trantypeval = item.get_value();

}


SUMMARY QUESTION:  What I need to retrieve from the combo box is the data loaded as the "value".  In the examples above, this would be either the 1, 2, or 3 -- not sell, rent, or trade.  How do I get the true selected value from the combo?

Thanks very much in advance!

Lynn




2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 28 Dec 2009, 01:28 PM
Hi Lynn,

You need to use the get_value() method of the RadComboBox client instance:

var b1 = $find("<%= ListTranType.ClientID %>");
alert(b1.get_value());


This should work in all cases. More info is available in our online documentation:

RadComboBox client side API

Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Lynn
Top achievements
Rank 2
answered on 28 Dec 2009, 02:44 PM
Veskoni,

As usual, you're correct. Your suggestion worked fine!  To be honest, I looked in various places to find that document that you referenced, but never saw that particular area/document.

Thanks!

Lynn
Tags
ComboBox
Asked by
Lynn
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Lynn
Top achievements
Rank 2
Share this question
or