Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>document.getElementByID() Issues

document.getElementByID() Issues

redux
11-24-2005, 03:42 AM
Hi all,

I have been tearing my hair out over the simplest of problems: document.getElementById() simply refuses to work for me. There's got to be something simple I'm missing, because I can't find anything on it.

I know the function doesn't work in all browsers, but I'm developing for IE6, so there's no problem there; but my script won't work in any browser.

Anyway, the code:

<html>
<head>
<script type="text/javascript">
<!--

function disp_toggle(id) {

id = document.getElementByID(id);

if (id.style.display = 'none') {

id.style.display = 'block';

} else if (id.style.display = 'block') {

id.style.display = 'none';

}


}
-->
</script>
</head>
<body>
<div id="disp" style="display: none;">Hidden Text</div>
<p><button onmousedown="disp_toggle('disp');">Click Me</button></p>
</body>
</html>
which yields a:
"document.getElementByID is not a function" (Firefox 1.5)

"message: Statement on line 6: Type mismatch (usually a non-object value used where an object is required)
Backtrace:
Line 6 of inline#1 script in url
id = document.getElementByID(id);" (Opera)

"Object doesn't support this property or method" (IE6)

I know there's got to be a stupid thing I'm missing, because hard-coding the div id into the getElement call doesn't work either. Thank you very much for helping.

gph
11-24-2005, 03:53 AM
if (id.style.display == 'none')
else if (id.style.display == 'block')

A1ien51
11-24-2005, 03:54 AM
quick look:
= assigns a value
== compares a value

Eric

redux
11-24-2005, 04:03 AM
Yeah, but that's still not the error I'm getting. I wrote the example in about 10 seconds to show it, the only important part is the getElementByID bit.

I could even simplify the code to:

<script>
function get_id(id) {
var id = document.getElementByID(id);
}
</script>

and it'd still throw an error. Thanks for the correction, though.

fci
11-24-2005, 04:05 AM
getElementByID != getElementById:
var id = document.getElementById(id);

and for an easy function call:
function $() { return document.getElementById(arguments[0]); }
var obj = $('my_id');

redux
11-24-2005, 04:10 AM
Wow. I'm amazed...that's the fastest solution I've ever seen. Thank you. I thought javascript wasn't case sensitive, but, whatever.


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

Hyperthreading hurts s
HP sharpens blade PC l
problem with an ImageP
Modifying a navigation
convert text to intege
Anyone knows to clear 
Automatically generate
document.getElementByI
Hi question about stor
Netscape Problems :-( 

News Archive

Month and Year drop do
navigation button/imag
doubt in window.open()
undo redo script 
Mimick "View Source" w
print Question 
No-image representatio
What's wrong with this
Urgent help in Javascr
Gurt Menu assistance 

Related stories:

Anyone knows to clear the contents of the window !!! in javascript
Automatically generates color tags(<color="red">,</color>)
Adding onclick stuff to an INPUT through javascript
Netscape Problems :-(
problem with an ImagePreview js
Can function RETURN a value?
do I need a random script script or not?

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics