homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Netscape 4 javascript problem
how can I acces an element using ID attribute?

 10:21 am on Mar 29, 2002 (gmt 0)

OK I really hope somebody can solve this for me. I have a form with numerous checkboxes, which I need to check/uncheck depending on user behaviour.

The form is posted through another page where it is dealt with using ASP, and so the checkboxes are all named the same so that this script can work.

Therefore I have used the id attribute to name them uniquely so that the javascript can access them individually. So, checkboxes take the form:

<input type="checkbox" name="samename" id="unique_1">
<input type="checkbox" name="samename" id="unique_2">

In IE, Opera and NS6 I can reference the checkboxes using:


However, in NS4, the browser seems to have no idea about the ID tags. Do I simply have to call them in a different way, or is this impossible? I really hope not, becasue otherwise I'm stuffed, as changing the names of the checkboxes will break the ASP application...



 12:29 pm on Mar 29, 2002 (gmt 0)

try using an array reference.


 12:41 pm on Mar 29, 2002 (gmt 0)

Does this means that I can't use the id attribute? It will be hard to use the array reference becuase the pages are dynamic, and so the number and position of checkboxes varies enormously...


 12:45 pm on Mar 29, 2002 (gmt 0)

why do you need the name the same for the asp? If your using vb then add a 1, 2 to the end then when you request the checkboxes do loop them and do a replace.


 12:50 pm on Mar 29, 2002 (gmt 0)

I haven't written the ASP code. I simply get the resulting HTML, but I fear that it may not be enough to work with unless I can use the ID tags.

It's not just a case of numbering them 1, 2, 3... either. The layout has multiple two dimensional matrices, so the numbering needs to be more like 'ID_1_0_1_3'. This is why accessing them correctly through the array reference is tricky.


 2:54 pm on Mar 29, 2002 (gmt 0)

Why not let the value of the "name" attribute be the same as the "id"?
Then, in NN4: document.forms[formName].chkboxName
and dom1 browsers: document.getElementById('chkboxName')


 2:58 pm on Mar 29, 2002 (gmt 0)

Sorry if I didn't explain properly, but all the name attributes are already fixed at a common string. That's why I was using the id attribute for the javascript code.


 3:14 pm on Mar 29, 2002 (gmt 0)

That's what doesn't make any sense. I think the ASP has to be the place that changes. What good are name tags in a room, if everyone is named Bob?


 3:19 pm on Mar 29, 2002 (gmt 0)

Thing is, the ASP works fine and so does the javascript, each with their own seperate naming conventions via name="" and id=""... except not in NS4. That is the problem.


 6:33 pm on Apr 3, 2002 (gmt 0)

why don't you try document.formname.elements[0]? Give this a try.


 6:54 pm on Apr 3, 2002 (gmt 0)

I think you have to do it with document.layers in Netscape 4, but I'm not sure as I've never tried it. You might find this page useful:


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved