This is a discussion on "Making CheckBox Selected" within the JavaScript Forum section. This forum, and the thread "Making CheckBox Selected are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Making CheckBox Selected
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Hi,
I'm having the following javascript code,after all the checkboxes are unslected,I'll display the alert to user saying that "Atleast one must be selected",but the checkbox is becoming unselected after throwing Alert,how to make check box to remain selected after throwing this alert. I'm calling this java script function in the onClick event of checkbox. var checkSelected = false; for (i = 0; i < planForm.locationOptions.length; i++) { if (planForm.locationOptions[i].checked) { checkSelected = true document.planForm.action='refreshPlanView.do';docu ment.planForm.submit(); document.getElementById("refreshing").style.displa y="block"; } } if (!checkSelected) { alert("At least ONE Location must be selected!"); return false; } return true; } Please advise.. Thanks, Kumar |
|
|
|
#2
|
||||
|
||||
|
Re: Making CheckBox Selected
uh wouldn't you have the alert, then on the next line code to make the checkbox selected?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#3
|
|||
|
|||
|
Re: Making CheckBox Selected
I didn't exactly understand the question/answer what you are trying to say?
|
|
#4
|
||||
|
||||
|
Re: Making CheckBox Selected
I'm not too good with explaining lately.
Sorry
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#5
|
||||
|
||||
|
Re: Making CheckBox Selected
If I'm understanding correctly, the alert is being thrown because no checkboxes are selected so this means they were all unselected before the alert anyway?
I think you could try passing the checkbox to the function so declare the function something like function checkboxcheck(obj) then in your checkboxes onclick="checkboxcheck(this)" and finally if (!checkSelected) { alert("At least ONE Location must be selected!"); obj.checked = true; return false; } This should keep the last checkbox checked at all times. Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
![]() |
| Tags |
| htmlp |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] Selected radio button value | Pugger | JavaScript Forum | 8 | Nov 3rd, 2007 14:16 |
| Required text field if Other selected from a list | redlevel | JavaScript Forum | 3 | May 16th, 2007 16:32 |
| How to view selected field only? | awiezzz | Classic ASP | 1 | May 13th, 2007 17:12 |
| Guide me how to show previously selected item in listbox | frmsasp | ASP.NET Forum | 1 | Jan 26th, 2006 15:37 |
| How to get value of selected dynamic checkboxes? | frmsasp | ASP.NET Forum | 1 | Nov 3rd, 2005 13:59 |