468,278 Members | 1,575 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,278 developers. It's quick & easy.

HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??

asd
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 td***@perfectsolve.com

Thanks in advance.
Jul 23 '05 #1
8 11269
On Mon, 08 Nov 2004 23:09:26 -0500, as*@asd.com wrote:
sub: Re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??
Please don't SHOUT, especially in your subject.
.... Please email replies to td***@perfectsolve.com


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
Jul 23 '05 #2
as*@asd.com wrote:
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 td***@perfectsolve.com


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>
Jul 23 '05 #3
RobG wrote:
[...]
<form action="" name="aForm"
onchange="addCurrent(this.optList1);">
<select name="optList1">


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.
Jul 23 '05 #4
On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
...
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?


(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
Jul 23 '05 #5
On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
..
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?


(shrugs) Let's find out..


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
Jul 23 '05 #6
Andrew Thompson wrote:
(shrugs) Let's find out..


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

Rob.
Jul 23 '05 #7
On Tue, 09 Nov 2004 06:36:24 GMT, Andrew Thompson <Se********@www.invalid>
wrote:
On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
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..


40tude Dialog - no. ;)


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.
Jul 23 '05 #8
On Tue, 09 Nov 2004 10:07:24 GMT, Michael Winter wrote:
On Tue, 09 Nov 2004 06:36:24 GMT, Andrew Thompson <Se********@www.invalid>
wrote:
On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
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..


40tude Dialog - no. ;)


Really? Odd. Opera does.


I was most interested in Google, but the thread had not surfaced there yet.
Now that post (and the thread) have..
<http://google.com/gr*****************************************@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
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Rahul | last post: by
23 posts views Thread by casper christensen | last post: by
15 posts views Thread by Jay | last post: by
8 posts views Thread by Greg Lyles | last post: by
9 posts views Thread by pic078 via AccessMonster.com | last post: by
16 posts views Thread by gnawz | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.