When I apply this to a <select> element (or DropDownList), I cannot save the original value to restore it later.
The following JavaScript is a "property" that loops through all of the controls associated with the custom confirm control and adds Listeners depending on the type of control it is.
Expand|Select|Wrap|Line Numbers
- set_AssociatedControlIDs: function(listOfControlIDs) {
- this._listOfControlIDs = listOfControlIDs;
- var len = this._listOfControlIDs.length;
- for (var i = 0; i < len; i++) {
- this._displayDelegate = Function.createDelegate(this, this._displayControl);
- this._saveOriginalDropDownListValueDelegate = Function.createDelegate(this, this.save_originalDropDownListSettings);
- var associatedControl = $get(this._listOfControlIDs[i]);
- if (associatedControl.type == 'select' || associatedControl.type == 'select-one') {
- $addHandler(associatedControl, 'change', this._displayDelegate);
- $addHandler(associatedControl, 'click', this._saveOriginalDropDownListValueDelegate);
- }
- else
- { $addHandler(associatedControl, 'click', this._displayDelegate); }
- }
- },
This method saves the <select> element that was clicked on and the current selected index:
Expand|Select|Wrap|Line Numbers
- save_originalDropDownListSettings: function(e) {
- this.dropDownList = e.target;
- this.originalDropDownListIndex = e.target.selectedIndex;
- e.preventDefault();
- e.stopPropagation();
- },
If the user clicks cancel, I call a the method that "restores" the selected index....well at least I'm attempting to restore the selected index:
Expand|Select|Wrap|Line Numbers
- restore_originalDropDownListSettings: function() {
- if (this.dropDownList != null && this.originalDropDownListIndex != null) {
- this.dropDownList.selectedIndex = this.originalDropDownListIndex;
- }
- },
Where am I going wrong here?
Is there a better way to cancel a select element's index change?
Thanks for your time,
-Frinny