determine checkbox most recently checked

Discussion in 'Javascript' started by pleaseexplaintome@yahoo.com, Dec 18, 2006.

  1. Guest

    Hi I need to determine the most recent check box that was checked.
    Let's say I have 5 checkboxes. CB 1 is checked and I then check CB 5.
    How do I know CB 5 was just checked, regardless of the fact CB 1 is
    checked? I don't care that CB 1 is checked, so looping thru the CB's
    won't help here. I cannot use radio buttons since I need unique names
    for the checkboxes. Thanks
     
    , Dec 18, 2006
    #1
    1. Advertising

  2. Erwin Moller Guest

    wrote:

    > Hi I need to determine the most recent check box that was checked.
    > Let's say I have 5 checkboxes. CB 1 is checked and I then check CB 5.
    > How do I know CB 5 was just checked, regardless of the fact CB 1 is
    > checked? I don't care that CB 1 is checked, so looping thru the CB's
    > won't help here. I cannot use radio buttons since I need unique names
    > for the checkboxes. Thanks


    Hi,

    Simply do it yourself.
    Add an eventhandler for onClick and store the value in a global var.

    Regards,
    Erwin Moller
     
    Erwin Moller, Dec 18, 2006
    #2
    1. Advertising

  3. Lee Guest

    said:
    >
    >Hi I need to determine the most recent check box that was checked.
    >Let's say I have 5 checkboxes. CB 1 is checked and I then check CB 5.
    >How do I know CB 5 was just checked, regardless of the fact CB 1 is
    >checked? I don't care that CB 1 is checked, so looping thru the CB's
    >won't help here. I cannot use radio buttons since I need unique names
    >for the checkboxes. Thanks


    Why do you believe that you need unique names for the boxes?
    Give them all the same name, but different values.


    --
     
    Lee, Dec 18, 2006
    #3
  4. Randy Webb Guest

    said the following on 12/18/2006 8:45 AM:
    > Hi I need to determine the most recent check box that was checked.
    > Let's say I have 5 checkboxes. CB 1 is checked and I then check CB 5.
    > How do I know CB 5 was just checked, regardless of the fact CB 1 is
    > checked? I don't care that CB 1 is checked, so looping thru the CB's
    > won't help here. I cannot use radio buttons since I need unique names
    > for the checkboxes. Thanks
    >


    onclick="var lastClicked=this.name"

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Dec 18, 2006
    #4
  5. In comp.lang.javascript message <>,
    Mon, 18 Dec 2006 10:48:17, Randy Webb <> wrote:
    > said the following on 12/18/2006 8:45 AM:
    >> Hi I need to determine the most recent check box that was checked.
    >> Let's say I have 5 checkboxes. CB 1 is checked and I then check CB 5.
    >> How do I know CB 5 was just checked, regardless of the fact CB 1 is
    >> checked? I don't care that CB 1 is checked, so looping thru the CB's
    >> won't help here. I cannot use radio buttons since I need unique names
    >> for the checkboxes. Thanks
    >>

    >
    >onclick="var lastClicked=this.name"


    That should indicate the last one clicked, not the last one checked.

    It seems immoral to have a var there; lastClicked should be initialised
    by var lastClicked = null or similar.

    I get the underlying action that the OP seems to need with

    <input type=checkbox onclick="if (this.checked) alert(9)">
    and
    <input type=checkbox onclick="if (this.checked) window.status++">

    It's a good idea to read the newsgroup and its FAQ. See below.

    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, Dec 18, 2006
    #5
  6. Evertjan. Guest

    Dr J R Stockton wrote on 19 dec 2006 in comp.lang.javascript:

    > <input type=checkbox onclick="if (this.checked) window.status++">


    window.status won't show in IE7


    >> onclick="var lastClicked=this.name"


    I would prefer saving an object pointer:

    <script type='text/javascript'>
    var lastClicked = null;
    </script>

    <input type='checkbox'
    onclick = 'if (this.checked) lastClicked = this'>

    <button
    onclick = 'lastClicked.checked = false'>
    Clear only the last checked checkbox
    </button>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Dec 19, 2006
    #6
    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. yurps
    Replies:
    1
    Views:
    6,997
    rajeshthangarasu1983
    Feb 29, 2008
  2. Wayne Wengert

    Determine Which Checkboxes are Checked

    Wayne Wengert, Feb 5, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,947
    Wayne Wengert
    Feb 5, 2006
  3. H.MuthuKumaraRajan
    Replies:
    3
    Views:
    492
    H.MuthuKumaraRajan
    Feb 4, 2004
  4. AllenLars
    Replies:
    0
    Views:
    250
    AllenLars
    May 7, 2009
  5. randy
    Replies:
    13
    Views:
    486
    Tad McClellan
    Nov 1, 2003
Loading...

Share This Page