/    Sign up×
Community /Pin to ProfileBookmark

Alternatives for accessing elements?

This is app is for PIE on PocketPC 2002.

It does not (at least ours don’t) support the DOM getElementByID() function. Nor does it support the document.all() function. I have tested both to verify this. I need to access elements by their IDs. These elements are not necessarily always form elements. (They are always in a form, however, they aren’t typical form input elements.) Example, a simple span element might have an ID that I want to access it by.

Are there any alternatives for doing this for those of us who are stuck with developing for browsers that are still in the dark ages?

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceApr 06.2005 — It it is in the dark ages, I'd be interested to know if it supports the [b]document.layers[/b] collection. ?
Copy linkTweet thisAlerts:
@JPnycApr 06.2005 — I don't suppose then that it supports the elements array either?
Copy linkTweet thisAlerts:
@phpnoviceApr 06.2005 — It does not (at least ours don't) support the DOM getElementByID() function. Nor does it support the document.all() function.[/QUOTE]
Perhaps you could walk down the DOM starting with [b]document.body.childNodes[/b] -- which is a collection. ...or, starting with [b]document.forms[0].childNodes[/b] ([b]document.forms[/b] being another "standard" collection).
Copy linkTweet thisAlerts:
@VladdyApr 06.2005 — What is wrong with plain HTML, you site does work with JS disabled, right?
Copy linkTweet thisAlerts:
@UltimaterApr 06.2005 — Check the document.getElementById link in my sig.

If that doesn't work.

define it like so:
[code=html]
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><!--
if(!document.getElementById){
document.getElementById=function(){
if(typeof window[arguments[0]] !="undefined")
return window[arguments[0]]
else
return null
}
}
//--></SCRIPT>
[/code]
Copy linkTweet thisAlerts:
@CurtMauthorApr 07.2005 — Check the document.getElementById link in my sig.

If that doesn't work.

define it like so:
[code=html]
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><!--
if(!document.getElementById){
document.getElementById=function(){
if(typeof window[arguments[0]] !="undefined")
return window[arguments[0]]
else
return null
}
}
//--></SCRIPT>
[/code]
[/QUOTE]


This and the code in your signature does not work on PPC. After debugging I have found it doesn't work for various reasons. Document.all and Document.layers are not supported. Even if they were, the PPC crashes when trying this:


document.getElementById=function(){ . . .

A normal IE browser will do that statement, but the PPC doesn't support it.
Copy linkTweet thisAlerts:
@KorApr 07.2005 — but if does not use:

document.all

nor

document.layers

nor

document.getElementById

[b]what[/b] kinda ECMA script do you think it may accept? None, upon my oppinion. It is like it would have javascript disabled, isn't it?
Copy linkTweet thisAlerts:
@crh3675Apr 07.2005 — It looks as if it supports some XML functions like:

var root = document.documentElement;

root.selectNodes("//span[@id='foo']")

So, couple that with a function

<i>
</i>
if(!document.getElementById){
document.getElementById=function(id){
var root=document.documentElement;
var coll=root.selectNodes("//*[@id='"+id+"'");
if(coll.length&gt;0){
return coll[0];
}else{
return null;
}
}
}


I haven't tried the code but I think it will work
Copy linkTweet thisAlerts:
@crh3675Apr 07.2005 — Ok, I tested this in regular IE

<i>
</i>&lt;html&gt;

&lt;script&gt;
//&lt;![CDATA[


if(!document.getElementByMyId){
document.getElementByMyId=function(id){
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var objNodeList;
xmlDoc.async = false;
xmlDoc.load(String(window.location).substring(String(window.location).lastIndexOf("/")+1));
var root=xmlDoc.documentElement;
objNodeList = root.selectNodes("//*[@id='"+id+"']");
if(objNodeList.length&gt;0){
return objNodeList[0];
}else{
return null;
}
}
}

alert(document.getElementByMyId("fart").tagName);
//]]&gt;
&lt;/script&gt;

&lt;body&gt;
&lt;div id="fart" style="height:200px"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;


Note that I changed the function call to "getElementByMyId" so I could test it.
Copy linkTweet thisAlerts:
@CurtMauthorApr 07.2005 — Ok, I tested this in regular IE

Note that I changed the function call to "getElementByMyId" so I could test it.[/QUOTE]


I couldn't get that to work in neither IE or PIE. Even after correcting the typo in the code for STRING. I'm guessing that it's an activeX thing that I may not have enabled in IE, and I'm guessing is not supported in PIE.

Also to answer a question of the other poster, I do have javascript enabled. Our app currently uses some javascript successfully in our version of PIE.
Copy linkTweet thisAlerts:
@crh3675Apr 07.2005 — The forum does strange things with code when it wraps, it was no typo and it works fine for me in IE 6
Copy linkTweet thisAlerts:
@phpnoviceApr 07.2005 — I couldn't get that to work in neither IE or PIE.[/QUOTE]
Did you consider/try this prior suggestion?
Perhaps you could walk down the DOM starting with [b]document.body.childNodes[/b] -- which is a collection. ...or, starting with [b]document.forms[0].childNodes[/b] ([b]document.forms[/b] being another "standard" collection).[/QUOTE]
Copy linkTweet thisAlerts:
@CurtMauthorApr 07.2005 — Did you consider/try this prior suggestion?[/QUOTE]

No, simply because that requires more knowledge about the DOM and JS than I currently have. :o
Copy linkTweet thisAlerts:
@UltimaterApr 07.2005 — Can you access an element via their ID by any of the following?
<i>
</i>&lt;SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"&gt;&lt;!--
onload=function(){
var myId="blah";
alert(document[myId])
alert(window[myId])
alert(document.layers[myId])
alert(eval(myId))
alert(document.all(myId))
alert(document.all[myId])
}
//--&gt;&lt;/SCRIPT&gt;
×

Success!

Help @CurtM spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...