• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array of checkboxes

 
Shashidahanu Iyyanar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shashidahanu Iyyanar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic