Hi All-
Problem: text from an elem is coming back as the text from the original
HTML, not the current, dynamic value. The DOM inspector and the screen
show the new value. the value from getElementById show the old value.
What gives ?
I have learned tonight that reading text from an element node is not
straightforward. I read some of the posts and have used
elem.firstchild.data. I wrote the HTML I am reading from. I use Firefox
(but I know most others don't. I have to be compatible, but that's for
later)
I start out with a hidden field set to an INIT value. I set a value as
a result of some tricky actions, _which work_ (a SQL query). I want to
read the result immediately after the SQL subroutine call, at the next
line. I use getElementById_s() (below) to get the element but that
should not matter. Here is the problem area
// .....
// check return result in a hidden field
var elem = getElementById_s('divZipCheckRes');
if ( null == elem ) {
window.alert( "introZipCheck() - Problem finding result?");
return false;
}
var tNode = elem.firstChild;
if ( "1" != tNode.data) {
window.alert( tNode.data + " Is that a valid California Zip
Code?");
return false;
}
return true;
----
the data returned in the alert() is the INIT value! But the screen
shows "1" (as does the DOM inspector). ideas appreciated...
----
// getElementById Special to handle quirky browsers
// most will use getElementById()
function getElementById_s(id){
var obj = null;
if(document.getElementById){
/* Prefer the widely supported W3C DOM method, if
available:-
*/
obj = document.getElementById(id);
}else if(document.all){
/* Branch to use document.all on document.all only
browsers. Requires that IDs are unique to the page
and do not coincide with NAME attributes on other
elements:-
*/
obj = document.all[id];
}
/* If no appropriate element retrieval mechanism exists on
this browser this function always returns null:-
*/
return obj;
}
----