I have a control that is supposed to allow the user to either allow or cancel what they were doing.
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.
So, now when the user clicks on the a <select> element associated with the control the "save_originalD ropDownListSett ings" method is called.
This method saves the <select> element that was clicked on and the current selected index:
If the <select> element associated with the control is changed (ie the selected index is changed) the control is displayed which allows the user to click Ok or Cancel.
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:
In this method the stored this.dropDownLi st is an <option> element (??) and the this.originalDr opDownListIndex is undefined.....t herefore the <select> element associated with the control is not reset to its original state.
Where am I going wrong here?
Is there a better way to cancel a select element's index change?
Thanks for your time,
-Frinny
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.
Code:
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:
Code:
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:
Code:
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
Comment