/    Sign up×
Community /Pin to ProfileBookmark

Get last option clicked in multi select box

Is there a way to pass the last option clicked to a JavaScript function/retrieve the value or index of the last option clicked using an onchange event?

I have a form with a multi select box. If the user has selected an option in the select box, an alert needs to pop up asking if selection is required or optional. However, if they are deselecting an option, no alert occurs.

So if user clicks options 2, 3, and 5 an alert box would come up each time, but if they went back and deselected option 3, no alert pops up.

Using MSIE

Thanks,

KTRI

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMay 20.2006 — In a multiple select, there is no provided method for determining the last option clicked when the Ctrl or Shift keys are held down in association with the click. The [b]selectedIndex[/b] property will always be the first selected option in the list. Thus, you would have to create an array with the same number of elements in it as the options in the select. Then, on each click, compare the array to the currently selected options in order to determine what had changed (the [I]delta[/I]) as a result of the last click.
×

Success!

Help @ktri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...