This is a discussion on "Help with must select at least one checkbox javascript function." within the JavaScript Forum section. This forum, and the thread "Help with must select at least one checkbox javascript function. are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Help with must select at least one checkbox javascript function.
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Help with must select at least one checkbox javascript function.
Hi,
I have a dynamic form with multiple checkboxes. I need to make sure that at least one checkbox is checked but only when the checkbox is actually unchecked. For example, the user unchecks 4 out of 5 boxes but when he unchecks box 5 an alert appears that one box must be checked and box 5 is left checked until he checks another and then unchecks box 5. I've written the following javascript function,but it is unchecking the check box after throwing the alert.I need to check the check box after throwing the alert.
Thanks for the help. Last edited by c010depunkk; Nov 28th, 2007 at 06:12. Reason: Please use [HTML] tags when posting HTML |
|
|
|
||||
|
Re: Help with must select at least one checkbox javascript function.
Your code would only work if all the boxes are unchecked or if the last box is unchecked. Try this:
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: Help with must select at least one checkbox javascript function.
Hi,
Thanks for the code,but it is also doing the same thing. I.e once the last check box is unchecked,it is throwing alert,but the checkbox is getting unselected.I need to keep the check box as selected after throwing alert and user clicking "Ok" on the alert. Thanks |
|
||||
|
Re: Help with must select at least one checkbox javascript function.
Not sure if this will work, but try this:
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: Help with must select at least one checkbox javascript function.
Hi,
Thanks for the input,but once the Alert is thrown it is checking the check box with value=0 as last_checked=0 has been declared,it is not checking the last unchecked check box. Please advise.. Thanks |
|
||||
|
Re: Help with must select at least one checkbox javascript function.
That's true, that was a logic error on my part....
I think a feasible solution would be to declare a global variable 'last_checked' and every time a check box is checked (in the onclick eventf), set this global variable to the value of that box. Then when the last one is unchecked, you could re-check the box who's value is stored in the global variable....
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| javascript show/hide function | danny322 | JavaScript Forum | 1 | May 15th, 2008 12:46 |
| add image src from javascript function | ktsirig | JavaScript Forum | 1 | Mar 14th, 2008 11:38 |
| Regarding select boxes in javascript | bhanu | Introduce Yourself | 5 | May 19th, 2007 12:45 |
| Select & View Checkbox | ktsirig | PHP Forum | 0 | Jan 23rd, 2006 11:13 |
| help with javascript function | kinjiro | JavaScript Forum | 1 | Nov 21st, 2003 15:58 |