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

Discussion in 'Javascript' started by smash2004@gmail.com, Oct 11, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. RobG Guest

    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
     
    RobG, Oct 11, 2005
    #2
    1. Advertising

  3. Guest

    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, 2005
    #3
  4. <> wrote in message news:...
    > 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=this.sel.options.selected;
    this.sel.options.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)


    if(this.optStates)
    this.sel.options.selected=false;
    }
    else
    if(this.multi)
    this.sel.options.selected=this.optStates;

    this.optStates=this.sel.options.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.
     
    Stephen Chalmers, Oct 11, 2005
    #4
  5. RobG Guest

    Stephen Chalmers wrote:
    > <> wrote in message news:...
    >
    >>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
     
    RobG, Oct 12, 2005
    #5
  6. RobG <> wrote in message news:3VZ2f.914$...
    > Stephen Chalmers wrote:
    > > <> wrote in message news:...
    > >

    > 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.
     
    Stephen Chalmers, Oct 12, 2005
    #6
  7. Lee Guest

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


    There's a sure sign of an amateur.
     
    Lee, Oct 12, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?R2Vvcmdl?=

    How to know which LinkButton clicked?

    =?Utf-8?B?R2Vvcmdl?=, Apr 6, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,760
    =?Utf-8?B?R2Vvcmdl?=
    Apr 6, 2004
  2. Bob
    Replies:
    3
    Views:
    1,416
  3. Oskar Wild
    Replies:
    2
    Views:
    167
    Oskar Wild
    Aug 28, 2003
  4. Bart Van der Donck

    which <option> was clicked on?

    Bart Van der Donck, Sep 6, 2003, in forum: Javascript
    Replies:
    5
    Views:
    94
    Bart Van der Donck
    Sep 7, 2003
  5. Replies:
    1
    Views:
    143
Loading...

Share This Page