Solved

How do i test if a radio button collection exists?

Posted on 2004-04-27
5
850 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
  • 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to check if a session is disconnected in php 9 32
Button function on table is in trouble 3 22
HTML Anchor Link Problem 3 38
javascript - insert into js doc help 2 25
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

830 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