By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

How to know which option in select field was clicked last?

P: n/a
i have a select field with multiple enabled so user can select multiple
options...

is it possible to get option that was clicked last...i need this
because i need to check if this option was already selected to deselect
it
thx for replys

Oct 11 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
sm*******@gmail.com wrote:
i have a select field with multiple enabled so user can select multiple
options...

is it possible to get option that was clicked last...i need this
because i need to check if this option was already selected to deselect
it


It's a bad idea to change the standard behaviour of a GUI element.
Users know to click once to select an item, ctrl+click selects an
extra one, shift+click selects a range, etc. If you change that, you
will probably confuse people.

Some use 'sticky keys' to do selections, other use voice activated
interfaces, others like to use purely keyboard navigation and not a
mouse. You can't possibly code for all those situations.

Those who learn your modified behaviour will then likely be stumped
when they go to some other site that uses the standard interface.

To achieve what you are after, cancel the default behaviour, then
simply toggle the selected property of whichever option is clicked on
- there is no need to remember the last one that was clicked on.

And expect your users to be utterly confused.

--
Rob
Oct 11 '05 #2

P: n/a
1.) I need to have this kind of behavior and period.

2.) I need to know what was the option that was clicked last because i
need to check if this option is already selected..if it is already
selected then i have to deselect it..I don't need to do this for every
other option except for the one that was selected last.

Get it?

Oct 11 '05 #3

P: n/a
<sm*******@gmail.com> wrote in message news:11*********************@g14g2000cwa.googlegro ups.com...
1.) I need to have this kind of behavior and period.

2.) I need to know what was the option that was clicked last because i
need to check if this option is already selected..if it is already
selected then i have to deselect it..I don't need to do this for every
other option except for the one that was selected last.

Get it?

Are you saying that if the user clicks on a currently selected option, that
option should be deselected, when normally nothing would happen?

Unfortunately, I.E does not support onclick for individual select options,
without which I can't see how to implement that behaviour.

Of course under Mozilla or Opera it's a doddle. Try this example, which
demonstrates two alternative select behaviours:

<HTML>
<BODY>

Normal behaviour preserved, except click toggles current option.
<FORM name='f1'>
<SELECT multiple name='s1'>
<OPTION value='red'>red
<OPTION value='green'>green
<OPTION value='blue'>blue
<OPTION value='black'>black
</SELECT>
</FORM>
<BR><BR>

Multiple Select using mouse only; shift/ctrl do not override.
<FORM name='f2'>
<SELECT multiple name='s1'>
<OPTION value='red'>red
<OPTION value='green'>green
<OPTION value='blue'>blue
<OPTION value='black'>black
</SELECT>
</FORM>

<SCRIPT type='text/javascript'>

function monitorSelect( objRef, sel, multi )
{
objRef=this;
this.sel=sel;
this.multi=multi;
this.optStates=[];

for(var i=0; i<this.sel.options.length; i++)
this.optStates[i]=this.sel.options[i].selected;
this.sel.options[i].onclick=function(){ objRef.recordStates(this) };
}
}

monitorSelect.prototype.recordStates=function(opt)
{
for(var i=0; i<this.sel.options.length; i++)
{
if(opt==this.sel.options[i])
if(this.optStates[i])
this.sel.options[i].selected=false;
}
else
if(this.multi)
this.sel.options[i].selected=this.optStates[i];

this.optStates[i]=this.sel.options[i].selected;
}
}

var selObj1=new monitorSelect(selObj1, document.forms.f1.s1, false);
var selObj2=new monitorSelect(selObj2, document.forms.f2.s1, true);

</SCRIPT>

</BODY>

--
S.C.
Oct 11 '05 #4

P: n/a
Stephen Chalmers wrote:
<sm*******@gmail.com> wrote in message news:11*********************@g14g2000cwa.googlegro ups.com...
1.) I need to have this kind of behavior and period.

2.) I need to know what was the option that was clicked last because i
need to check if this option is already selected..if it is already
selected then i have to deselect it..I don't need to do this for every
other option except for the one that was selected last.

Get it?


Are you saying that if the user clicks on a currently selected option, that
option should be deselected, when normally nothing would happen?

Unfortunately, I.E does not support onclick for individual select options,
without which I can't see how to implement that behaviour.

Of course under Mozilla or Opera it's a doddle. Try this example, which
demonstrates two alternative select behaviours:


You've made an admirable ('zilla only) attempt, but the arrow keys
defeat you. Click on two 'f2' options in sequence, then use an up (or
down) arrow key - only one option remains selected.

Subsequent clicks cause behaviour that, so someone who doesn't know what
is happening under the hood, is quite confusing.

Using script to re-program default UI behaviour nearly always fails.
On-screen help is simpler and less prone to error:

"Use control + click to select multiple options"

[...]
--
Rob
Oct 12 '05 #5

P: n/a
RobG <rg***@iinet.net.au> wrote in message news:3V*****************@news.optus.net.au...
Stephen Chalmers wrote:
<sm*******@gmail.com> wrote in message news:11*********************@g14g2000cwa.googlegro ups.com...

You've made an admirable ('zilla only) attempt, but the arrow keys
defeat you. Click on two 'f2' options in sequence, then use an up (or
down) arrow key - only one option remains selected.

Subsequent clicks cause behaviour that, so someone who doesn't know what
is happening under the hood, is quite confusing.

Using script to re-program default UI behaviour nearly always fails.


I knew that, but I set out to demonstrate only the requested mouse-based selection,
which in practice is never going to be implemented, at least not with select boxes.

--
S.C.
Oct 12 '05 #6

P: n/a
Lee
sm*******@gmail.com said:

1.) I need to have this kind of behavior and period.


There's a sure sign of an amateur.

Oct 12 '05 #7

P: n/a

<sm*******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
1.) I need to have this kind of behavior and period.

2.) I need to know what was the option that was clicked last because i
need to check if this option is already selected..if it is already
selected then i have to deselect it..I don't need to do this for every
other option except for the one that was selected last.


Um am I being stupid but the one clicked last will be the currently selected
option !

Please provide more information ?
Oct 12 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.