Connecting Tech Pros Worldwide Help | Site Map

HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??

  #1  
Old July 23rd, 2005, 04:13 PM
asd@asd.com
Guest
 
Posts: n/a
I need to find the value/index of the previously selected item of a
select list. That is, when the user selects an item from the list and
a certain condition elsewhere in the form is not met, I need to
display an alert box warning the user that a selection cannot be made,
and redisplay the item that was previously selected. What is the most
efficient way of doing this?

Please email replies to tdk13@perfectsolve.com

Thanks in advance.


  #2  
Old July 23rd, 2005, 04:13 PM
Andrew Thompson
Guest
 
Posts: n/a

re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??


On Mon, 08 Nov 2004 23:09:26 -0500, asd@asd.com wrote:
[color=blue]
> sub: Re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??[/color]

Please don't SHOUT, especially in your subject.
....[color=blue]
> Please email replies to tdk13@perfectsolve.com[/color]

How much are you prepared to pay for this personal service?

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
  #3  
Old July 23rd, 2005, 04:13 PM
RobG
Guest
 
Posts: n/a

re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??


asd@asd.com wrote:[color=blue]
> I need to find the value/index of the previously selected item of a
> select list. That is, when the user selects an item from the list and
> a certain condition elsewhere in the form is not met, I need to
> display an alert box warning the user that a selection cannot be made,
> and redisplay the item that was previously selected. What is the most
> efficient way of doing this?
>
> Please email replies to tdk13@perfectsolve.com[/color]

Here is a posted solution:

Create a global array when the page is loaded. When the user selects
each selection, put the selected item index into the array using
push().

If the current selection fails your test, pop the last item off the end
of the array, the new last item in the array will be the index of the
previous selection. You can keep poping the last one off until there
are none left - at this point, reset the form.

If you only want to remember the last one and not all the previous
ones, then just set a single variable and replace it with each
successive successful selection.

Cheers, Rob.

<script type="text/javascript">

// Global array to store selection indexes
selectedItems = new Array();

// Adds current selection index to array
function addCurrent(a){
var x = a.options;
for (var i=0;i<x.length; i++) {
if (x[i].selected) {
selectedItems.push(i);
}
}
}

function selectLast(a) {
var x = a.options;
if (selectedItems.length <= 1) {

// alert is optional
alert('No previous selection, resetting list');

// clear array and reset form
selectedItems.pop();
a.parentNode.reset();
} else {

// clear last item from array, set selected to
// new last item (previous index)
selectedItems.pop();
var p = selectedItems[selectedItems.length-1];
a.options[p].selected = true;
}
}
</script>
<form action="" name="aForm"
onchange="addCurrent(this.optList1);">
<select name="optList1">
<option value="opt0">
<option value="opt1">Option 1
<option value="opt2">Option 2
<option value="opt3">Option 3
<option value="opt4">Option 4
</select>
<input type="button" value="Back to previous"
onclick="selectLast(this.form.optList1);">
<input type="reset">
</form>
  #4  
Old July 23rd, 2005, 04:13 PM
RobG
Guest
 
Posts: n/a

re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??


RobG wrote:
[...][color=blue]
> <form action="" name="aForm"
> onchange="addCurrent(this.optList1);">
> <select name="optList1">[/color]

Ooops, sorry, I put the "onchange" on the wrong element. Worked fine
in Firefox but IE barfed. Testing, testing, testing... should read:

<form action="" name="aForm">
<select name="optList1" onchange="addCurrent(this);">

As a point of interest, I hate people who yell their subject lines,
however if I reduce it to lower case, will it still thread OK in most
reader agents?

Cheers, Rob.
  #5  
Old July 23rd, 2005, 04:13 PM
Andrew Thompson
Guest
 
Posts: n/a

re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??


On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
...[color=blue]
> As a point of interest, I hate people who yell their subject lines,
> however if I reduce it to lower case, will it still thread OK in most
> reader agents?[/color]

(shrugs) Let's find out..

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
  #6  
Old July 23rd, 2005, 04:13 PM
Andrew Thompson
Guest
 
Posts: n/a

re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??


On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
[color=blue]
> On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
> ..[color=green]
>> As a point of interest, I hate people who yell their subject lines,
>> however if I reduce it to lower case, will it still thread OK in most
>> reader agents?[/color]
>
> (shrugs) Let's find out..[/color]

40tude Dialog - no. ;)

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
  #7  
Old July 23rd, 2005, 04:13 PM
RobG
Guest
 
Posts: n/a

re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??


Andrew Thompson wrote:
[color=blue]
> (shrugs) Let's find out..
>[/color]

LOL! The best chuckle I've had in quite a while... ;-)

Rob.
  #8  
Old July 23rd, 2005, 04:13 PM
Michael Winter
Guest
 
Posts: n/a

re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??


On Tue, 09 Nov 2004 06:36:24 GMT, Andrew Thompson <SeeMySites@www.invalid>
wrote:
[color=blue]
> On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
>[color=green]
>> On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
>>[color=darkred]
>>> [...] if I reduce it to lower case, will it still thread OK in
>>> most reader agents?[/color]
>>
>> (shrugs) Let's find out..[/color]
>
> 40tude Dialog - no. ;)[/color]

Really? Odd. Opera does.

I thought the point of the References header was to thread messages. The
first message id is that of the first post in the thread. The second id
refers to the second post, and so on. Using the subject should be a fall
back at most.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
  #9  
Old July 23rd, 2005, 04:13 PM
Andrew Thompson
Guest
 
Posts: n/a

re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??


On Tue, 09 Nov 2004 10:07:24 GMT, Michael Winter wrote:
[color=blue]
> On Tue, 09 Nov 2004 06:36:24 GMT, Andrew Thompson <SeeMySites@www.invalid>
> wrote:
>[color=green]
>> On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
>>[color=darkred]
>>> On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
>>>
>>>> [...] if I reduce it to lower case, will it still thread OK in
>>>> most reader agents?
>>>
>>> (shrugs) Let's find out..[/color]
>>
>> 40tude Dialog - no. ;)[/color]
>
> Really? Odd. Opera does.[/color]

I was most interested in Google, but the thread had not surfaced there yet.
Now that post (and the thread) have..
<http://google.com/groups?selm=frslp9q1fqt8$.1rd5c6latrv7y.dlg@40tude .net>

Follow the 'View: Complete Thread..' for the result.
[ Yes, Google groups threads it correctly. ]

If Opera and ..Mozilla Thunderbird 0.8 and OE thread it correctly,
I think the answer to the question is..

"Yes, it threads OK in (most) reader agents."

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed in retrieving the selected values in the next page.:) ajos answers 9 February 2nd, 2008 12:19 PM
Retrieving info from another table in a form. Frankie answers 3 November 13th, 2005 04:28 AM
rs.Edit instead of rs.AddNew dixie answers 25 November 12th, 2005 11:02 PM
rs.Edit instead of rs.AddNew dixie answers 25 November 12th, 2005 10:36 PM