Welcome to WebmasterWorld Guest from 54.161.201.189

Forum Moderators: open

Netscape 4 javascript problem

how can I acces an element using ID attribute?

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

10+ Year Member



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:

document.formname.elements['unique_1']

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)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



try using an array reference.
12:41 pm on Mar 29, 2002 (gmt 0)

10+ Year Member



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)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

10+ Year Member



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)

10+ Year Member



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)

10+ Year Member



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)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

10+ Year Member



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)

10+ Year Member



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:

[xs4all.nl...]

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month