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

determine checkbox most recently checked

P: n/a
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 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
pl***************@yahoo.com 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
Dec 18 '06 #2

P: n/a
Lee
pl***************@yahoo.com 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.
--

Dec 18 '06 #3

P: n/a
pl***************@yahoo.com 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/
Dec 18 '06 #4

P: n/a
In comp.lang.javascript message <JY********************@telcove.net>,
Mon, 18 Dec 2006 10:48:17, Randy Webb <Hi************@aol.comwrote:
>pl***************@yahoo.com 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.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 18 '06 #5

P: n/a
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)
Dec 19 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.