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

RadComboBox from js

15 Answers 316 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Zÿm
Top achievements
Rank 1
Zÿm asked on 23 Dec 2011, 01:49 PM
hi,
 I am doing some testing. I need to change radComboBox selected value from javascript. How can i achieve that? But it is rendered to list...what is necessary to set ? ClientState is not enough...

15 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Dec 2011, 06:06 AM
Hello,

Try the following.
JS:
<script type="text/javascript">
function OnClientSelectedIndexChanged(sender, args)
  {
    var text = sender.get_selectedItem().get_text();
    sender.set_text(text);
     sender.set_value(text);
  }
</script>

Thanks,
Princy.
0
Zÿm
Top achievements
Rank 1
answered on 26 Dec 2011, 03:10 PM
Eghm....it is more complicated...I want to change already rendered radCombobox value. I have no problem with other inputs such as select, input...As i said i am doing some web ui testing. Thanks.
0
Zÿm
Top achievements
Rank 1
answered on 27 Dec 2011, 09:38 AM
If i add to css "li.rcbHovered" and in input write text, would this save radComboBox value?
0
Ivana
Telerik team
answered on 27 Dec 2011, 10:03 AM
Hi,

Could you clarify a little bit more what exactly is your scenario?

To learn how to use the client-side API of the RadComboBox, you could refer to the following documentation section: RadComboBox / Client-side Programming.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Zÿm
Top achievements
Rank 1
answered on 27 Dec 2011, 02:08 PM
   I don't know, how to explain it...I know about client-side of RadComboBox. But i need to set value already on published website through javascript.
  To make it simpler here is a simple example: if i want to change textbox value i just write with js:

var txt = document.getElementById('ct00_window_txtName');
txt.value = 'new value';

So how to change value of radComboBox? Because it is rendered not to select input, but to the list.
0
Ivana
Telerik team
answered on 28 Dec 2011, 09:03 AM
Hello,

Try the following:
var combo = $find('<%= RadComboBox1.ClientID%>')
//Find item by its text.
var item = combo.findItemByText("item1");
if(item){
  //When setting an item as selected will automatically show its text in the RadComboBox's input area.
  item.select();
   
  //To set text in the input area, you can also use the following:
  combo.set_text(item.get_text());
}
//Or find item by its value.
combo.findItemByValue("item1_value").select();

I hope this helps.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Zÿm
Top achievements
Rank 1
answered on 28 Dec 2011, 10:55 AM
How is this helpful? You basically posted the same answer as before. Have you even read these posts? I don't know how to make my self clearer. I thought i could find answer more faster here I guess i will need to find on my own.
 
Ok, maybe then you can answer this, here is a rendered RadComboBox, and there is a ctl00_window_Form_Organization_ClientState input, for what it is used?

<div id="ctl00_window_Form_Organization">
<table summary="combobox">
<tr class="rcbReadOnly">
<td>
<input name="ctl00$window$Form$Organization" type="text" id="ctl00_window_Form_Organization_Input" value="value 1" readonly="readonly" />
</td>
<td>
<a id="ctl00_windowContent_Form_Organization_Arrow">select</a>
</td>
</tr>
</table>
<!-- 2011.3.1115.40 -->
<div>
<div id="ctl00_window_Form_Organization_DropDown">
<div>
<ul>
<li class="rcbItem ">value 1</li>
<li class="rcbItem ">value 2</li>
<li class="rcbItem ">value 3</li>
<li class="rcbItem ">value 4</li>
<li class="rcbItem ">value 5</li>
<li class="rcbItem ">value 6</li>
</ul>
</div>
</div>
</div>
<input id="ctl00_window_Form_Organization_ClientState" name="ctl00_window_Form_Organization_ClientState" type="hidden" />
</div>

Hope is for sissies.
Kind regards 

0
Ivana
Telerik team
answered on 28 Dec 2011, 01:22 PM
Hi,

The input with ID="ctl00_window_Form_Organization_ClientState" is a hidden field, and it it used to transfer data from client to server and vice versa. The purpose of this input is to transfer data only -- its logic is implemented in the RadComboBox control, and should not be accessed or altered by the users.

As in the code provided in your previous post, the RadComboBox is rendered with the following ClientID:
ctl00_window_Form_Organization. Now, you can use this ID to get the RadComboBox client object:
$find("ctl00_window_Form_Organization");
Having the client object of RadComboBox, you could change its value and text, using the client API of the control.
//Change the value of the RadComboBox object itself.
$find("ctl00_window_Form_Organization").set_value("my value");
//Change the value of the RadComboBox object by selecting an item.
$find("ctl00_window_Form_Organization").get_items().getItem(0).select();

To alter the value of the input DOM element of RadComboBox input area, you could do the following:
$get("ctl00_window_Form_Organization_Input").value = "my value";
$get is a AJAX representation of the document.getElementById JavaScript method.

If you are still having troubles, in order to help you, we will need more information about the scenario you are trying to achieve. If the issues you are experiencing are still not resolved, you could send us a support ticket on this matter, where a sample page could be attached.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Zÿm
Top achievements
Rank 1
answered on 02 Jan 2012, 10:37 AM
Ok thanks for your time. This still does not answer the question. I don't really understand, is this very hard question, that you misunderstanding it. I found other way how to change it, but thanks anyway :). By the way i had problem not only with RadCombobox, but with RadDate... pickers.
0
Ivana
Telerik team
answered on 03 Jan 2012, 12:43 PM
Hello,

I am glad you were able to resolve your scenario.  Could you share the solution,  so that the whole forum community could benefit from it?

Greetings,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Zÿm
Top achievements
Rank 1
answered on 03 Jan 2012, 02:53 PM

1. I am finding arrow anchor by its id.
2. initiate click 
3. finding li element by text (or link=day_number if calendar)
4. initiate click

but is very inconvenient. I am wondering how to save value to "_ClientState elements". Is this good Ivana? have i shared the answer?
0
Ivana
Telerik team
answered on 05 Jan 2012, 02:14 PM
Hello,

Yes, this is a right approach when working directly with html elements:

1. Click on RadCombobBox arrow - represented by A with id = ComboID_Arrow.
2. Wait for RadComboBox items to appear.
3. Click on particular RadComboBox item - represented by LI element.


As for the input with ID: [RadComboBox_ID]_ClientState, the value could be accessed using the element's attribute: value, as in the following example:
$get([RadComboBox_ID] + "_ClientState").value = "my value"; 

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Alberto
Top achievements
Rank 1
answered on 19 Aug 2015, 06:39 PM
Hi Ivana, I know the post is old, but how do you click on the Li Items?  I can get the LI Items in a link, and click on the Arrow.
0
Alberto
Top achievements
Rank 1
answered on 19 Aug 2015, 06:41 PM
Hi Zym, I have a similar issue, how did you find the Li Items?  and then clicked on them?  I'm stuck with javascript.
0
Eyup
Telerik team
answered on 24 Aug 2015, 07:54 AM
Hello Alberto,

Could you elaborate on what exactly you want to achieve? You can also send us sample screenshots or video demonstrating the required behavior. Thus, we will be able to figure out your specific scenario and prepare a sample web site to send it to you.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Zÿm
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Zÿm
Top achievements
Rank 1
Ivana
Telerik team
Alberto
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or