[Javascript] Firefox issue with checkbox selection

David Dorward david at dorward.me.uk
Wed Mar 14 03:37:04 CDT 2007


Alan Easton wrote:
> I need some help with a piece of code, that checks to see if any 
> checkboxes are selected or not. It works fine in IE, but not in Firefox. 
> I know it is a GetElementByID issue, but I cannot fix it.

No such function. There is document.getElementById (which is case 
sensitive).

> The JS function is called by: <a 
> href="javascript:DeleteProperties()">DELETE</a>

Don't do that.
http://www.jibbering.com/faq/#FAQ4_24
Use a regular submit button and use the onsubmit handler to cancel the 
event if the user hasn't picked any items.

> function DeleteProperties()
> {
>  var i,sel;
>  sel = 0;
>  for(i = 0; i < mylist.propID.length; i++)      //this line

You haven't defined "mylist".

>  {
>   if(mylist.propID(i).checked)                      //and this one
>   {
>    sel = 1;

You set sel to 1 here ...

>   }
>  }
>  if(sel != 1)
>  {

And then make a decision based on it here. Why not just do this action 
if you reach the end of the loop ...

>   alert("Deletion of Selected Properties\n\nYou must first select some 
> properties to delete.");
>  }
>  else
>  {
>   if(confirm("Are you sure you wish to delete these properties?"))

... and this one if you get a match, and then return from it there?

You don't actually use getElementById (or GetElementByID).

> Now with Firefox, it needs to reference the "id" attribute in each 
> checkbox, and I have it, the name and id attributes for each checkbox 
> are the same. I have highlighted the 2 problem lines above.

You highlighted? Can't see any indicators here.

-- 
David Dorward                               <http://dorward.me.uk/>



More information about the Javascript mailing list