Re: Reading value from label (DIV) with JS
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Reading value from label (DIV) with JS

From: Ivo <no@thank.you>
Date: Mon Aug 08 2005 - 22:09:47 CEST

"Mateo" wrote
>
> For example, in IE I can use this:
> value = document.form1.lblMyLabelControl.innerText;
> but, innerText property is not compatibile with W3 DOM, so mozilla doesn't
> support this.

Try this:
    value = document.form1.lblMyLabelControl.firstChild.nodeValue;
or:
    value = document.form1.lblMyLabelControl.firstChild.data;

The first child of the element is the textnode (if it isn't, the element
contains other stuff too, and you need to navigate the DOM some more),
which has a property "nodeValue" containing the text you are looking for.
All W3 DOM-compatible, all Mozilla-fähig.

> It would be also nice to find universal way for setting text for label or
> values in INPUT fields, but I would be pretty satisfied only with reading
> text from label...

This nodeValue thing is even read/write, so a statement like:

    document.form1.lblMyLabelControl.firstChild.nodeValue = 'Some new text';

would set the displayed text to, well, some new text.

There are other ways.
hth
ivo
http://4umi.com/
Received on Mon Oct 24 02:13:54 2005