[Javascript] IE/FF, getElementById and checkboxes

Peter Brunone peter at brunone.com
Wed Apr 30 22:28:02 CDT 2008


Hi Alan,

    The second line is choking because you're treating delusers like a function instead of an array.  Remember, collection elements use brackets in C-syntax languages (this still trips me up sometimes):

if (actform.delusers[i].checked)    

    The first line's trouble is a bit more difficult to track down.  The actual error message would be helpful, so we don't have to guess at what the complaint was; if I had to guess, I'd say you need to include more of the tree hierarchy, i.e.

document.actform.delusers

or even

document.forms.actform.delusers

...but it's hard to say what the actual problem is without knowing what error was thrown.  You did open the Javascript console (by typing javascript: in the address bar and hitting Enter), right?  If not, do that and run the page again; report the error message here and we'll take a more informed shot at the problem.

Cheers,

Peter

----------------------------------------

From: Alan Easton alaneaston666 at hotmail.com

Hi All,
 
I have some validation that works in IE, for when I need to check if any checkboxes are checked in my form. If there are, then I submit the form.
 
Code is below:
 
------------------------------------------------
 
< script   language ="JavaScript">
  function  delArts()
{
 var  i,sel;
sel = 0;
 for (i = 0; i < actform.delusers.length; i++)    <----THIS LINE
{
 if (actform.delusers(i).checked)                    <---THIS LINE
{
sel = 1;
}
}
 if (sel != 1)
{
alert( "Deletion of Users\n\nYou must first select some users to delete." );
}
 else
 {
 if (confirm( "Are you sure you wish to delete these users?" ))
{
actform.submit();
}
}
}
 </ script > 
  
Example checkbox field: 
<input type="checkbox" value="5" name="delusers"> 
  
All are called "delusers", and have different values. Now I know I need to ad "id"'s to all of these, but I am still having trouble.
  
------------------------------------------------
 
However this is not working in FF. I know I need to change to use getElementById, but the two lines highlighted above are causing me problems.
 
Any help would be appreciated in order so the validation works in IE and Ff.
 
Thanks,
 
Alan...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20080430/3f9586ca/attachment.htm>


More information about the Javascript mailing list