determine checkbox most recently checked

P

pleaseexplaintome

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
 
E

Erwin Moller

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
 
L

Lee

(e-mail address removed) 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.


--
 
R

Randy Webb

(e-mail address removed) 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"
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>,
(e-mail address removed) said the following on 12/18/2006 8:45 AM:

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.
 
E

Evertjan.

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


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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top