Jump to content

Validate checkbox


robert_gsfame

Recommended Posts

again problem with checkbox...i am really newbie at javascript so hope that anyone could help :P

 

i have this function

function check()

{

if((document.getElementById('id1').checked==false)&&(document.getElementById('id2').checked==false)){

alert('please check at least one checkbox');}else{

alert('Are you sure?');}

 

if there are 2 records with id=id1 and id=id2 then no problem will occur, what if let assume no record for id1 or in other words Null?? i have tried the above code but not working

 

Thx for your help!

  }

Link to comment
https://forums.phpfreaks.com/topic/196009-validate-checkbox/
Share on other sites

i also tried this but not working

 

function check()

{

var a=0;

for(i==1;i<3;i++){

if(document.getElementbyId(i)!==null){

if(document.getElementbyId(i).checked==false){

a++;}}}

if(a==0){

alert('Please choose at least one');}else{

alert('thx for choosing');}

  }

Link to comment
https://forums.phpfreaks.com/topic/196009-validate-checkbox/#findComment-1029575
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.