Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12143 > unrolled thread

How to programmatically display a value

Started by" Cal Who" <CalWhoNOSPAM@roadrunner.com>
First post2012-02-24 20:19 -0500
Last post2012-02-27 17:40 +0100
Articles 7 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  How to programmatically display a value " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-24 20:19 -0500
    Re: How to programmatically display a value " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-24 21:25 -0500
      Re: How to programmatically display a value Swifty <steve.j.swift@gmail.com> - 2012-02-25 06:46 +0000
      Re: How to programmatically display a value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-25 13:19 +0100
        Re: How to programmatically display a value Dr J R Stockton <reply1208@merlyn.demon.co.uk> - 2012-02-26 20:38 +0000
        Re: How to programmatically display a value Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-02-27 15:53 +0100
          Re: How to programmatically display a value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-27 17:40 +0100

#12143 — How to programmatically display a value

From" Cal Who" <CalWhoNOSPAM@roadrunner.com>
Date2012-02-24 20:19 -0500
SubjectHow to programmatically display a value
Message-ID<ji9cvn$pqa$1@dont-email.me>
I calculate and want to display the numerical result.

I can do it by assigning to the value attribute of an <input type=text>
element.

However, I don't want the user to be able to change the value displayed.

I tried readonly="readonly" but, unless I had a bug in the code, I found I
couldn't programmatically change the value displayed by assigning to value.

How should I do that?

Thanks


[toc] | [next] | [standalone]


#12144

From" Cal Who" <CalWhoNOSPAM@roadrunner.com>
Date2012-02-24 21:25 -0500
Message-ID<ji9grj$a07$1@dont-email.me>
In reply to#12143
I don't know if this is the "best" way to display a numeral but I found the 
innerHTML property on the span element and that appears to work OK.

" Cal Who" <CalWhoNOSPAM@roadrunner.com> wrote in message 
news:ji9cvn$pqa$1@dont-email.me...
>I calculate and want to display the numerical result.
>
> I can do it by assigning to the value attribute of an <input type=text>
> element.
>
> However, I don't want the user to be able to change the value displayed.
>
> I tried readonly="readonly" but, unless I had a bug in the code, I found I
> couldn't programmatically change the value displayed by assigning to 
> value.
>
> How should I do that?
>
> Thanks
>
>
> 

[toc] | [prev] | [next] | [standalone]


#12147

FromSwifty <steve.j.swift@gmail.com>
Date2012-02-25 06:46 +0000
Message-ID<4s0hk7p0f9stvvtklnh90jffvvg2tkd1pu@4ax.com>
In reply to#12144
On Fri, 24 Feb 2012 21:25:47 -0500, " Cal Who"
<CalWhoNOSPAM@roadrunner.com> wrote:

>I found the 
>innerHTML property on the span element and that appears to work OK

Hopefully it will work perfectly, as that is more or less exactly what
it was intended to do.

-- 
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk

[toc] | [prev] | [next] | [standalone]


#12163

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-25 13:19 +0100
Message-ID<1403837.V9SEqChMir@PointedEars.de>
In reply to#12144
 Cal Who wrote:

> I don't know if this is the "best" way to display a numeral but I found
> the innerHTML property on the span element and that appears to work OK.

You are displaying a numeral, not parsing HTML markup; using innerHTML is 
overkill, not standardized, and therefore error-prone.  Use the `nodeValue' 
property of the `firstChild' of the span element object (you should provide 
it with a child node, say <span>&nbsp;</span>).

Your learning to quote (at least, not to top-post) is a prerequesite for my 
further considering your postings.  You have been warned.


PointedEars
-- 
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
  -- Richard Cornford, comp.lang.javascript, 2011-11-14

[toc] | [prev] | [next] | [standalone]


#12193

FromDr J R Stockton <reply1208@merlyn.demon.co.uk>
Date2012-02-26 20:38 +0000
Message-ID<mpQ2z2KwgpSPFwAc@invalid.uk.co.demon.merlyn.invalid>
In reply to#12163
In comp.lang.javascript message <1403837.V9SEqChMir@PointedEars.de>,
Sat, 25 Feb 2012 13:19:29, Thomas 'PointedEars' Lahn
<PointedEars@web.de> posted:

OK, now we know how to deal with him.


The answers seen so far have ignored the most important consideration,
which is that of what the designer of the application wants the output
to look like.

Sometimes the output should form part of a running sentence, in which
case writing into a SPAN element is best. Or maybe an I or a B or a TT
element, if the output should be italic or bold or monospace; or CSS can
be used to style the element.

But if something resembling a form is used, perhaps with FIELDSETs,
buttons, checkboxes etc., it may well be appropriate to use an output
element that looks like a little window, such as is (or was) often found
on measuring instruments; and an INPUT TYPE=TEXT READONLY serves well
for that, especially if READONLY elements are given, as is done by
Safari, a slightly non-white background.


The two lines of code that someone gave to set an element with
getElementById and .innerHTML should, if used more than about twice, be
implemented in a function :
      function Wryt(ID, S) { document.getElementById(ID).innerHTML = S }
unless of course the reference is saved for future use.


The OP (and others) might read
<http://www.merlyn.demon.co.uk/js-faq-u.HTM#MaWP>.


> Cal Who wrote:
>
>> I don't know if this is the "best" way to display a numeral but I found
>> the innerHTML property on the span element and that appears to work OK.
>
>You are displaying a numeral, not parsing HTML markup; using innerHTML is
>overkill, not standardized, and therefore error-prone.  Use the `nodeValue'
>property of the `firstChild' of the span element object (you should provide
>it with a child node, say <span>&nbsp;</span>).
>
>Your learning to quote (at least, not to top-post) is a prerequesite for my
>further considering your postings.  You have been warned.

-- 
 (c) John Stockton, nr London UK.  ?@merlyn.demon.co.uk  DOS 3.3, 6.20; WinXP.
  Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links.
   PAS EXE TXT ZIP via  <http://www.merlyn.demon.co.uk/programs/00index.htm>
   My DOS  <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

[toc] | [prev] | [next] | [standalone]


#12200

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2012-02-27 15:53 +0100
Message-ID<4f4b98cd$0$6909$e4fe514c@news2.news.xs4all.nl>
In reply to#12163
On 2/25/2012 1:19 PM, Thomas 'PointedEars' Lahn wrote:
>   Cal Who wrote:
>
>> I don't know if this is the "best" way to display a numeral but I found
>> the innerHTML property on the span element and that appears to work OK.
>
> You are displaying a numeral, not parsing HTML markup; using innerHTML is
> overkill, not standardized, and therefore error-prone.  Use the `nodeValue'
> property of the `firstChild' of the span element object (you should provide
> it with a child node, say<span>&nbsp;</span>).
>

Thomas,

Why did you say using innerHTML is error-prone?

Are you saying it is error-prone *because* it is not standardized?
Or it it error-prone for a different reason?

I ask because I never encountered any problems using innerHTML for 
simple tasks like displaying a number.
What is it are you warning for here?

Regards,
Erwin Moller


-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

[toc] | [prev] | [next] | [standalone]


#12202

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-27 17:40 +0100
Message-ID<1963616.aqSPkdTlGX@PointedEars.de>
In reply to#12200
Erwin Moller wrote:

> On 2/25/2012 1:19 PM, Thomas 'PointedEars' Lahn wrote:
>> Cal Who wrote:
>>> I don't know if this is the "best" way to display a numeral but I found
>>> the innerHTML property on the span element and that appears to work OK.
>>
>> You are displaying a numeral, not parsing HTML markup; using innerHTML is
>> overkill, not standardized, and therefore error-prone.  Use the
>> `nodeValue' property of the `firstChild' of the span element object (you
>> should provide it with a child node, say<span>&nbsp;</span>).
> 
> Why did you say using innerHTML is error-prone?
> 
> Are you saying it is error-prone *because* it is not standardized?
> Or it it error-prone for a different reason?

Both.

> I ask because I never encountered any problems using innerHTML for
> simple tasks like displaying a number.

Because it is a simple task and it is only a number string, not markup, 
`innerHTML' is overkill.  It is also proprietary and error-prone.  
Therefore, it is best avoided here.

> What is it are you warning for here?

We really have discussed this ad nauseam here.  To reiterate: The 
`innerHTML' property facilitates only a proprietary de-/serialization of the 
document tree, entirely at the discretion of the implementor.  Among other 
things, this means that you can write to the `innerHTML' property but you 
cannot know if this worked.  There is no exception thrown and reading back 
the property value very likely yields a different string value than the one 
you previously wrote to it.  `innerHTML' breaks with tables, except when you 
generate the whole table with `innerHTML'.  `innerHTML' also (very 
obviously) is not supposed to work in XHTML.  All this is very different 
with the standardized DOM manipulation methods.


PointedEars
-- 
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
  -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web