Solved

How do i test if a radio button collection exists?

Posted on 2004-04-27
5
853 Views
Last Modified: 2012-06-27
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
Comment
Question by:Darren_Fryer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10936113
Hi Darren_Fryer,

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

BFN,

fp.
0
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 250 total points
ID: 10936117
...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
 

Author Comment

by:Darren_Fryer
ID: 10936197
Thank you very much!
isObject worked brilliantly.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10936222



  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
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10936284
Hi again,

Thanks for the points/grading.

Happy codin',

BFN,

fp.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question