469,903 Members | 1,993 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Workaround for document.getElementById("mydiv").style.display='no ne'

Hi,

I have an onchange method for a select box that goes something like
this (the select is in a form named aForm):

function page_on_change() {
pageElement = aForm.my_page_id;
aForm.nav_page_name.value =
pages[pageElement.options[ pageElement.selectedIndex ].value];
var si = pageElement.selectedIndex;
for ( i = 0 ; i < pages.size ; i++ ) {
document.getElementById("id_" + i).style.display='none';
}
document.getElementbyId("id_" + si).style.display='none';
}

IE fails on the statement:

document.getElementbyId("id_" + si).style.display='none';

and says it doesn't support this property.

What is the workaround?

Thanks.

Mar 16 '07 #1
4 69660
IE fails on the statement:
>
document.getElementbyId("id_" + si).style.display='none';
Capitalize 'By' in getElementById. Javascript is case-sensitive.

Mar 16 '07 #2
Thanks Walton,

Great catch.

Now a message popus up that says Object required.

I've eyeballed the source and confirmed that divs id_0,id_1 etc exist.
On Mar 16, 12:29 pm, "Walton" <jrhol...@gmail.comwrote:
IE fails on the statement:
document.getElementbyId("id_" + si).style.display='none';

Capitalize 'By' in getElementById. Javascript is case-sensitive.

Mar 16 '07 #3
Opps. I got it. Thanks.

Mar 16 '07 #4
gi*******************@yahoo.com wrote :
Thanks Walton,

Great catch.

Now a message popus up that says Object required.

You are not correctly accessing form elements.
I have an onchange method for a select box that goes something like
this (the select is in a form named aForm):

function page_on_change() {
pageElement = aForm.my_page_id;
aForm.nav_page_name.value =
pages[pageElement.options[ pageElement.selectedIndex ].value];
You must access the form element like this:

document.forms["aForm"]
and not like
aForm

Accessing Elements with the W3C DOM
http://developer.mozilla.org/en/docs...th_the_W3C_DOM

Referencing Forms and Form Controls by comp.lang.javascript newsgroup
FAQ notes
http://jibbering.com/faq/faq_notes/form_access.html

Referencing Forms and Form elements correctly, Javascript Best
Practices, by Matt Kruse
http://www.javascripttoolbox.com/bestpractices/#forms

Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)
http://developer.mozilla.org/en/docs...your_Web_Pages
Mar 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Erwin Moller | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.