HopfZ wrote on 30 jun 2006 in comp.lang.javascript
:
Evertjan. wrote:
r = EBI3['myText']
or:
r = EBI3.myText
Both returns null (without error).
You are right, my mistake.
getElementById needs an (argument)
--------- test.html ----------------
<html>
<head>
<title>test</title>
<script language="javascript">
use <script type='text/javascript'>
function load(){
function assert(b,s){ if(!b) alert('false is\n'+s);}
function EBI2(id){return document.getElementById(id)};
var EBI3 = document.getElementById;
document.EBI4 = document.getElementById;
assert(EBI2('myText'),'EBI2 works');
assert(EBI3['myText']==null,'EBI3["myText"] returns null');
Do not test for null, test for existence. see below.
assert(EBI3.myText==null,'EBI3.myText returns null');
assert(document.EBI4.myText==null, 'document.EBI4 works');
document.EBI4.myText does not work too !!!!!
alert('end of load');
}
</script>
</head>
<body onload="load();">
<form id="myForm">
<input type="text" id="myText"></input>
</input> is not html
</form>
</body>
</html>
Try this:
<html>
<head>
<script type='text/javascript'>
function load(){
function assert(b,s){ if(!b) alert(s);}
function EBI2(id){return document.getElementById(id)};
var EBI3 = document.getElementById;
document.EBI4 = document.getElementById;
assert(EBI2('myText'),'EBI2 error'); // OK SKIPS
assert(EBI3['myText'],'EBI3["myText"] error'); // ERRORS
assert(EBI3.myText,'EBI3.myText error'); // ERRORS
assert(document.EBI4.myText, 'document.EBI4 error'); // ERRORS
alert('end of load');
}
</script>
</head>
<body onload="load();">
<form>
<input type="text" id="myText">
</form>
</body>
</html>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)