0
votes

I am displaying an HTML list box using some computed fields and a repeat control. It works great, including a pager which pages the list box selections.

Now I want an onclick event for the list box. The client side click event needs to populate a field. My click event works fine but I can't figure out how to get a handle to the field.

In a client click event in designer, I could simply do something like: document.getElementById("#{id:lastSelected}").value = namesSelected;

but this does not appear to work for me as I am not really going through designer so #{id:lastSelected} is not defined correct?

Is there anyway I can make my option line clickable so that I can add the event through the designer?

Or is there someway that "#{id:lastSelected}" can be resolved within my client javascript for the way I am doing it? Maybe call an XSP function?

Here is the computed field that creates the first part of the listbox, notice how I am doing the onclick event.

 var id = "id='" + getClientId("searched") +"ListBox'";     //Generate a unique id for the list box using the computed field name   
 var size= "size=" + compositeData.listBoxSize.toString();  
 var style = "style='width:275px;'";
 var multi = (compositeData.multipleSelect==true) ? "multiple" : ""     
 return "<select " +id + " " + size + " " + style + " " + multi + " onclick='searchedListBoxSingleLeftClick();'>";

Here is how I compute each option line, this computed field is inside the repeat control

 var name = rowData.getColumnValues()[1]; 
 return "<option " + " id='" + rowData + "' value='" + rowData.getUniversalID() + "'>" + name + "</option>"
1

1 Answers

2
votes

Bruce - just like in the Name Picker custom control I sent you, you can use a scriptBlock to surface the id of the component you need:

var lastSelected = "#{id:lastSelected}";

Then, in your client javascript you can reference that variable:

dojo.byId(lastSelected).value = namesSelected