File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Array of checkboxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Array of checkboxes" Watch "Array of checkboxes" New topic

Array of checkboxes

Shashidahanu Iyyanar
Ranch Hand

Joined: Jun 22, 2005
Posts: 37
Hi All,
I am having an list of checkboxes having the same name and there is a submit button.The following scenarios have to be checked:
1) If the user clicks on the submit button without checking any one of the checkboxes,the user should be presented with a alert message stating that "Any one of the checkboxes has to be checked".
2) If the user checks any one or more of the checkboxes znd clicks on the submit button,the user should be presented with a confirmation message screen stating that "Do you want to delete?".

How to achieve the above mentioned scenarios using Javascript?A example would be much better.Thanks in advance.
Debashree Halder
Ranch Hand

Joined: Jul 27, 2005
Posts: 81
Try this code inside script tag:

function call(){

var count=0;

for(var i=1;i<7;i++){
var ch=document.getElementById('chk'+i);

alert("Any one of the checkboxes has to be checked");
alert("Do you want to delete?");


and then create 6 chk boxes in a form inside body tag and call the function 'call()' on clicking the button Submit.

Hope that would serve your purpose...


Debashree Halder<br />SCJP 1.5<br />Washington DC
Shashidahanu Iyyanar
Ranch Hand

Joined: Jun 22, 2005
Posts: 37
Thanks for the reply and the suggestion given by you with a example.It has solved my problem.Last but not the least,thanks.
I agree. Here's the link:
subject: Array of checkboxes
It's not a secret anymore!