wood burning stoves*
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
Author

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);
if(ch.checked==true){
count++;}
}

if(count==0)
alert("Any one of the checkboxes has to be checked");
if(count>0)
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


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

Joined: Jun 22, 2005
Posts: 37
Hi,
Thanks for the reply and the suggestion given by you with a example.It has solved my problem.Last but not the least,thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Array of checkboxes
 
Similar Threads
Capture list of checked rows from JSP
How to display the submited date in jsp
problem when visiting same page again
submit button
handling the input type check box in struts