Re: shortcut for document.getElementById and some error
- From: "Evertjan." <exjxw.hannivoort@xxxxxxxxxxxx>
- Date: 30 Jun 2006 18:04:03 GMT
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)
.
- References:
- shortcut for document.getElementById and some error
- From: HopfZ
- Re: shortcut for document.getElementById and some error
- From: Evertjan.
- Re: shortcut for document.getElementById and some error
- From: HopfZ
- shortcut for document.getElementById and some error
- Prev by Date: Re: possible to store javascript document.forms[0].value to ASP session?
- Next by Date: Re: Problem with .innerHTML, AJAX and Firefox
- Previous by thread: Re: shortcut for document.getElementById and some error
- Next by thread: WWW/Internet 2006: Call for Papers (Murcia, Spain)
- Index(es):
Relevant Pages
|