?
Solved

How do i test if a radio button collection exists?

Posted on 2004-04-27
5
Medium Priority
?
854 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 1000 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

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.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

770 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