cancel
Showing results for 
Search instead for 
Did you mean: 

Client Code for adding items to a sap:ListBox

Former Member
0 Kudos

Hi,

1) Can i add values to a ListBox manually with javascript at the client ?

2) How do I find the sap:Controls with javascript?

I have noticed, that the id of the controls is changed to something_controlID

thanx

Message was edited by: Erhan Tamer

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

1 The ListBox as all the other SAP controls is a server side control, which means there is no reason to add items to the ListBox in the browser. This item is not added to the ListBox on the server and selecting this item in the browser will have no affect on the Selected property of the ListBox.

2 As you have noticed the SAP control id is in the form of something_controlID which is a unique id on the page. the id is the combination of a unique string and the name you gave to the control in design time. the rendered control can be one or more html tags.

Message was edited by: Reffael Caspi

Former Member
0 Kudos

Hi Reffael,

first of all thank you for responding.

1.

As I reproduced in the html code, the rendered controls can be several html tags, as you mentioned.

You said that there is no reason to add items to the ListBox in the Browser.

Please be careful with statements such as this. There is at least one very good reason to fill a ListBox on the Client: Providing an opportunity to the user, to preselect all desired arguments, without commiting a roundtrip to the server. And this is a very good reason, I think.

Even some server controls like the "DropDownByKey" do not prevent the user making operations on that controls at client side.

2.

This is not an anwser to my question. I want to know:

How do I find an SAP:Control in javascript. This means is there a way to get to know the given "unique string" ?

Message was edited by: Erhan Tamer

Former Member
0 Kudos

Hi Erhan

1. I didn't say u can't manuipulate existing items in the ListBox, I said u can't add new items to the ListBox.

In order to select items you can use the sapUrMapi_ItemListBox_setSelectedKeys( Id , Keys , Doc ) javascript method

Id - string Identifier of the control

Keys - string Array of keys to be selected

Doc - DOMDocument 'document' object of the browser

2. You can use the ClientID property in the server side in order to know the id used in the html on the client side.

For example:

taken from the ASPX page

<script language="javascript">

function productChanged(eventObj)

{

...

<%= Form.ID + "." + prdID.ClientID %>.value = product_ID;

<%= Form.ID + "." + prdName.ClientID %>.value = product_name;

<%= hSubmit.ClientID %>.click();

}

</script>