3.2.0

Get Combo Box Value From Button

Assume I have:

var obj = new AW.UI.Combo();
obj.setId("staffCombo");
obj.setItemCount(myStaffVals.length);
obj.setItemText(myStaffVals);
obj.setItemValue(myStaffKeys);
document.write(obj);

and

var obj = new AW.UI.Button();
obj.setId("staffAdd");
obj.setControlText("Add Staff To Location");
obj.onControlClicked = function(event) {
window.location = "/wv_dev/client/addCommssionedStaff.asp?LID=<%= Request("LID") %>&PID=<%= Request("PID") %>&SID=";
};
document.write(obj);

How do I access the current, selected value of staffCombo in the onControlClicked of staffAdd?

Thanks.
Paul Tiseo
April 6,
It's nice to be able to provide support to yourself!

var staffCombo = new AW.UI.Combo();
staffCombo.setId("staffCombo");
staffCombo.setItemCount(myStaffVals.length);
staffCombo.setItemText(myStaffVals);
staffCombo.setItemValue(myStaffKeys);
// make combo more <select>-like
staffCombo.getContent("box/text").setAttribute("readonly", true); 
staffCombo.onControlEditStarted = function() {
     this.getContent("box/text").element().contentEditable = false;
} 
document.write(staffCombo);


and

var staffAdd = new AW.UI.Button();
staffAdd.setId("staffAdd");
staffAdd.setControlText("Add Staff To Location");
// button click action
staffAdd.onControlClicked = function(event) {
     var sel_val = staffCombo.getItemValue(staffCombo.getSelectedItems());
     window.location = "/wv_dev/client/addCommissionedStaff.asp?LID=<%=Request("LID") %>&PID=<%= Request("PID") %>&SID=" + sel_val;
};
document.write(staffAdd);


Caveat: Not sure if my code in onControlClicked is the best way to trigger a page change. Probably there is a more AW way of doing this via Button properties and methods that I have yet to discover...
Paul Tiseo
April 7,
Please correct the first line in the onControlClicked block for the button to:

var sel_val = myStaffKeys[staffCombo.getSelectedItems(staffCombo.getSelectedItems())];


This gets the actual <option> value, what I call the "key". The code in the above post gets you the position of the data of the combo in the array used to populate it.

My bad. Sorry.
Paul Tiseo
April 7,

This topic is archived.

See also:


Back to support forum