Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 857
  • Last Modified:

How do i test if a radio button collection exists?

Hello, I have the below code:

            for(i=0; i<document.form1.PackageID.length; i++) {
                  if(document.form1.PackageID[i].checked==true) {
                        if((document.form1.PackageID[i].value)!='') {
                              PackageSelected = 1;
                        }
                  }
            }

I have XML dynamically generating a run of <input type=radio>'s on the fly with the NAME="PackageID", But if this FOR loop attempts to test before the radio's exist I get an error:
document.form1.PackageID.length is null or not an object

Can i test like an isExist or isNull in javascript? If so, is that what i use?
Thanks in advance...
0
Darren_Fryer
Asked:
Darren_Fryer
  • 3
1 Solution
 
[ fanpages ]IT Services ConsultantCommented:
Hi Darren_Fryer,

This link may help :)
http://www.crockford.com/javascript/remedial.html

BFN,

fp.
0
 
[ fanpages ]IT Services ConsultantCommented:
...specifically:

function isNull(a) {
    return typeof a == 'object' && !a;
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isFunction(a) {
    return typeof a == 'function';
}


BFN,

fp.
0
 
Darren_FryerAuthor Commented:
Thank you very much!
isObject worked brilliantly.
0
 
ZvonkoSystems architectCommented:



  rBttn = document.form1.PackageID;
  if(rBttn){
     if(rBttn.length){
         for(i=0; i<rBttn.length; i++) {
              if(rBttn[i].checked==true) {
                   if((rBttn[i].value)!='') {
                        PackageSelected = 1;
                   }
              }
         }
    }else{
       if(rBttn.checked && rBttn.value!=""){
         PackageSelected = 1;
       }
    }
  }



0
 
[ fanpages ]IT Services ConsultantCommented:
Hi again,

Thanks for the points/grading.

Happy codin',

BFN,

fp.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now