[Javascript] IE/FF, getElementById and checkboxes

Alan Easton alaneaston666 at hotmail.com
Thu May 1 03:19:57 CDT 2008


Sorry guys, I should have included errors...DOH.
 
I have firebug on my FF, and like you have said, the first error is for:
 
if(actform.deluser(i).checked) <----- actform.deluser is not a function
 
And there is a note for: 
Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead - undefined
 
So I guess those are for the 2 lines I highlighted.
 
This has always confused me, but in using getElementById, how do you write out the for loop instance differently: for(i = 0; i < actform.deluser.length; i++)
 
I tried document.getElementById('deluser').length, but that did not seem to work.
 
I will try your ideas. Thanks again for your help.
 
Alan...


Date: Wed, 30 Apr 2008 20:28:02 -0700From: peter at brunone.comTo: javascript at lists.evolt.orgCC: Subject: Re: [Javascript] IE/FF, getElementById and checkboxesHi 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.delusersor evendocument.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... 
_________________________________________________________________
Bag extra points with the Walkers Brit Trip Game 
http://www.walkersbrittrips.co.uk/game
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20080501/c6b8f1bd/attachment.htm>


More information about the Javascript mailing list