By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

Text from an Element, w/ a twist

P: n/a
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;
}
----
Jan 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a


one man army wrote:

I start out with a hidden field set to an INIT value.
What HTML element exactly, a hidden input e.g.
<input type="hidden" name="inputName" value="INIT">
I set a value as
a result of some tricky actions, _which work_ (a SQL query).


What kind of "value" do you set, how do you do that, post the code, at
least outline it. SQL queries usually happen on the server while most
issues we are dealing here with are client-side JavaScript, and what you
have below looks like client-side JavaScript.
If you have the browser connect to the server so that it does an SQL
query then we need to know how you do that.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 20 '06 #2

P: n/a
In article <43***********************@newsread2.arcor-online.net>,
Martin Honnen <ma*******@yahoo.de> wrote:
one man army wrote:

I start out with a hidden field set to an INIT value.


What HTML element exactly, a hidden input e.g.
<input type="hidden" name="inputName" value="INIT">


oh.. not knowing, I used a <div> then tried to get the text out.
Setting the value was easy. I set it to "1" on success, or the SQL error
or my own error msg on failure. Perhaps I should use an INPUT type TEXT,
and that would be easier/more reliable to get text back out of.
I set a value as
a result of some tricky actions, _which work_ (a SQL query).


What kind of "value" do you set, how do you do that, post the code, at
least outline it. SQL queries usually happen on the server while most
issues we are dealing here with are client-side JavaScript, and what you
have below looks like client-side JavaScript.
If you have the browser connect to the server so that it does an SQL
query then we need to know how you do that.


yeah, that matters, but it is a little involved.

What I noticed after the post was that I often get the _previous_
result. So the first time through, I get the INIT text. A second time
through, I get the FIRST result back. Even though the screen has
apparently been updated.

I am wondering if I need to chain events in order to handle and kind of
latency. Can I initiate a click or somesuch, the return, and on the
click handler read the value and process? This is something I had used
in tricky situations in a previous programming environment.

further thoughs on this welcome, 'cause right now the page does not
work. thanks
Jan 20 '06 #3

P: n/a
um, perhaps poor wording in the response. POST means something in this
group, I meant 'after writing the newsgroup response'.

what I am trying to acheive is an update in place on a web page using
Javascript events and the DOM. I am all the way through coding the
action, and now I am simply trying to interpret the response, which has
been set inside a DOM element. I am getting some kind of delay/latency
problem reading the reponse.

So I am asking if chaining events is ever done here. When the event
that initiated the action completes, it initiates another event as its
last action. I then handle that event and the latency is settled down.
Am I getting warmer?

thanks
Jan 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.