Select/Unselect script does not work on firefox

Dear Experts hi,
  I am using the following script to select/unselect all select boxes on a form named reg. The select boxes are named c1 to c10
 The form declaration is as follows:

 <form id="reg" name="reg" method="post" action="something.php">
<a href="javascript:checkAll()">Select/Unselect All</a>    
<input name="c1" type="checkbox" id="something" value="1" />
.
.
.
<input name="c10" type="checkbox" id="something" value="10" />

 </form>

I have the firebug installed on my firefox and it gives me the error in question...
The funny thing is that I have set up another html page to use this script and it works great on firefox but not on the template I am using. I dont know if there is someother javascrpt code that I allready have set up on this template that conflicts and causes the error
reg is not defined var chkObj = eval('reg.' + chkArr[count]);

...either way any help will be appreciated. And of course if you need more info please ask. Thanks a lot...
function checkAll(){
	 		
            var chkArr = ["c1","c2","c3","c4","c5","c6","c7","c8","c9","c10"];
 
            var frmObj = document.getElementById('reg');
 
 
            for(var count=0;count < chkArr.length;count++){
                  var chkObj = eval('reg.' + chkArr[count]);
                  if(typeof(chkObj) != "undefined"){
                        chkObj.checked = !chkObj.checked;
                  }
            }
      }

Open in new window

atsalisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashish PatelCommented:
Try this


function checkAll(){
	 		
            var chkArr = ["c1","c2","c3","c4","c5","c6","c7","c8","c9","c10"];
            //var frmObj = document.getElementById('reg');
 
            for(var count=0;count < chkArr.length;count++){
                  var chkObj = document.getElementsByName('reg.' + chkArr[count])[0];
                  if(chkObj && chkObj.type == "checkbox"){
                        chkObj.checked = !chkObj.checked;
                  }
            }
      }

Open in new window

0
hieloCommented:
The problem is here:
 var chkObj = eval('reg.' + chkArr[count]);

It doesn't know that reg is a child of document.forms. Fix:
var chkObj = eval('document.forms.reg.' + chkArr[count]);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
atsalisAuthor Commented:
Thanks a lot it worked...however can I ask you why it used to work they way I did it before on another page?...? Do you think there may be some other Javascript tht I have that conflicts with that one?
0
hieloCommented:
>>Do you think there may be some other Javascript tht I have that conflicts with that one?
No.

>>why it used to work they way I did it before on another page
Can't tell for sure. One possibility is that "reg" on another page may have been a shortcut for
document.forms.reg
Ex:
var reg = document.forms.reg

then when evaled as you did, then it should work.
0
atsalisAuthor Commented:
Ok I guess that sets it...thanks a lot mate....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.