473,508 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Restore Selected Value on Cancel

Frinavale
9,735 Recognized Expert Moderator Expert
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.
Expand|Select|Wrap|Line Numbers
  1. set_AssociatedControlIDs: function(listOfControlIDs) {
  2.         this._listOfControlIDs = listOfControlIDs;
  3.         var len = this._listOfControlIDs.length;
  4.         for (var i = 0; i < len; i++) {
  5.             this._displayDelegate = Function.createDelegate(this, this._displayControl);
  6.             this._saveOriginalDropDownListValueDelegate = Function.createDelegate(this, this.save_originalDropDownListSettings);
  7.  
  8.             var associatedControl = $get(this._listOfControlIDs[i]);
  9.             if (associatedControl.type == 'select' || associatedControl.type == 'select-one') {
  10.  
  11.                 $addHandler(associatedControl, 'change', this._displayDelegate);
  12.                 $addHandler(associatedControl, 'click', this._saveOriginalDropDownListValueDelegate);
  13.             }
  14.             else
  15.             { $addHandler(associatedControl, 'click', this._displayDelegate); }
  16.         }
  17.     },
So, now when the user clicks on the a <select> element associated with the control the "save_originalDropDownListSettings" method is called.

This method saves the <select> element that was clicked on and the current selected index:
Expand|Select|Wrap|Line Numbers
  1. save_originalDropDownListSettings: function(e) {
  2.         this.dropDownList = e.target;
  3.         this.originalDropDownListIndex = e.target.selectedIndex;
  4.  
  5.         e.preventDefault();
  6.         e.stopPropagation();
  7.     },
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:
Expand|Select|Wrap|Line Numbers
  1. restore_originalDropDownListSettings: function() {
  2.         if (this.dropDownList != null && this.originalDropDownListIndex != null) {
  3.             this.dropDownList.selectedIndex = this.originalDropDownListIndex;
  4.         }
  5.     },
In this method the stored this.dropDownList is an <option> element (??) and the this.originalDropDownListIndex is undefined.....therefore 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
Mar 5 '09 #1
6 3495
Dormilich
8,658 Recognized Expert Moderator Expert
what object refers "this" to, maybe the problem lies there (especially since event handlers change the context of "this")?
Mar 5 '09 #2
Frinavale
9,735 Recognized Expert Moderator Expert
"this" refers to my Object.
Mar 5 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
and you are sure, that this' context is not changed to anything else?
Mar 6 '09 #4
Frinavale
9,735 Recognized Expert Moderator Expert
Double checking:

"this" is the Object in the method saves which <select> was clicked and it's original selected index.

"this" is the same Object in the method that should restore the <select> to its original selected value.


Why, then, are the values saved null in the method that restores the <select>?
Expand|Select|Wrap|Line Numbers
  1. save_originalDropDownListSettings: function(e) {
  2.    this.dropDownListsID = e.target.id;
  3.    this.originalDropDownListIndex = e.target.selectedIndex;
  4.  
  5.    e.preventDefault();
  6.    e.stopPropagation();
  7. },
  8. restore_originalDropDownListSettings: function() {
  9.    if (this.dropDownListID != null && this.originalDropDownListIndex != null) {
  10.      $get(this.dropDownListID).selectedIndex = this.originalDropDownListIndex;
  11.    }
  12. },
Also, why is it going into the If block since this.dropDownLIstID is null???
Mar 6 '09 #5
Frinavale
9,735 Recognized Expert Moderator Expert
Oh wait I think I see a type-o!

Right, I fixed the type-o but I'm still having the same problem..........
Expand|Select|Wrap|Line Numbers
  1. save_originalDropDownListSettings: function(e) {
  2.    this.dropDownListID = e.target.id;
  3.    this.originalDropDownListIndex = e.target.selectedIndex;
  4.  
  5.    e.preventDefault();
  6.    e.stopPropagation();
  7. },
  8. restore_originalDropDownListSettings: function() {
  9.    if (this.dropDownListID != null && this.originalDropDownListIndex != null) {
  10.      $get(this.dropDownListID).selectedIndex = this.originalDropDownListIndex;
  11.    }
  12. },
Mar 6 '09 #6
Frinavale
9,735 Recognized Expert Moderator Expert
I solved the problem.

Here's what was happening:
  • The user clicks the select element
    • The original selected index was saved
  • The user selects a new value
    • The onchange event was executed...
    • The onclick event for the option selected....
      • the option's onclick event bubbled up to the Select element's onclick
  • The index was being saved again, but it couldn't because it was an option type

To get around this I saved a boolean value which indicated that the index had already been saved....if this was true, then the value would not be saved again.


-Frinny
Mar 6 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
15450
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that...
2
37613
by: jbmccluskey | last post by:
I'm a newbie so please be gentle. In attempting to run a restore I get the following error message: "Exclusive access could not be obtained because the database is in use." However, it doesn't...
3
4014
by: jforena | last post by:
Hi, I am trying to create a javascript that will display a confirmation message when a user submits a form and has specifically selected a particular radio button. For example: <form...
2
2538
by: D. Dante Lorenso | last post by:
First I created a function that selected the next available pin code from a table of pre-defined pin codes: CREATE FUNCTION "public"."get_next_pin_code" () RETURNS varchar AS' DECLARE...
3
9094
by: deko | last post by:
I have a form with a subform datasheet - I need code behind the OnDelete event of the subform: Private Sub Form_Delete(Cancel As Integer) 'do something that depends on which record is deleted...
7
11165
by: ChrisR | last post by:
Hi guys My app is a simple Main form with a few Subforms that are not linked, and a few pop forms. Problem is: I have a pop form with a Listbox with a list of records related to the...
6
3659
by: Raj | last post by:
How can we do an online restore of a tablespace using the incremental backup's? we are on a partitioned database... Also, how could we use backup copy made by the load (using the copy to option...
1
2744
by: destiny007 | last post by:
can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse...
2
3383
beacon
by: beacon | last post by:
Hi everybody, I have a form that has a combo box that asks the user to select the program they work on. Once the user selects the program, a SQL statement populates the row source for 4 staff...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.