473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
7 1742
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
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
<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
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
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
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

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Oskar Wild | last post by:
Hello, how do I code it to display a select (pulldown) box only if the user has selected a certain option in another pulldown box? <select name=country> <OPTION value="France" SELECTED>France...
5
by: Bart Van der Donck | last post by:
Hello, My hair falls out! Is it possible to retrieve the "ordering value" of the <option> that was clicked inside a range of options ? In other words, with something like <option...
4
by: Old Lady | last post by:
Hi, I need help! I have a SELECT/OPTION list. My goal is to have a TEXT input field in a form that is normally disabled, but it should become enabled when the user select one predefined OPTION....
1
by: Liz Malcolm | last post by:
Hello and TIA. I have a DE form with an option group that if daily is selected todays date is used for start and end date, if weekly is selected Monday - Friday is used. I am trying to add a...
3
by: ANTISPAM_garycnew_ANTISPAM | last post by:
What is the simplest way to retain the last option value selected in an html select object using javascript? I am currently using a server-side cgi language to accomplish this task, but it adds...
5
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
1
by: Stephen D Cook | last post by:
In my form I have an option group with 3 option buttons. My form is tied to a table. the options are Temp, Permanent and Overtime. I have these inside a frame. I have an AddRecord button to enter...
5
by: Matthew Wells | last post by:
I have a listbox set to simple multi select. For this example, users only select one item at a time. I have command buttons on the form for First, Previous, Next, Last, New (record). The form...
8
by: Raul | last post by:
Hi, I have a select list that gets populated from the DB. When the user makes a selection I am able to retrieve this value via Request.Form(...) However, I am wondering if you can retrieve...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.