What's wrong with the field value assignment?

20 views
Skip to first unread message

justaguy

unread,
Jun 18, 2013, 5:33:28 PM6/18/13
to
Hi,

I attempted to assign one field's value to anther but am not getting anywhere, and wonder what's wrong with the code below, see Line 3.

<form>
<input id="name1">
<input id="name2">
...
</form>

<div id="nameX"></div>

var n = 2;
var nm = document.getElementById('name'+n).value;
document.getElementById('nameX').value = nm; // line 3

Thanks in advance.
Message has been deleted

justaguy

unread,
Jun 18, 2013, 7:27:32 PM6/18/13
to
On Tuesday, June 18, 2013 5:44:49 PM UTC-4, Tim Streater wrote:
> In article <c737a6d5-2315-4a6a...@googlegroups.com>,
> I expect a <div> doesn't have a value, it has a textContent.
>
>
>
> --
>
> Tim
>
>
>
> "That excessive bail ought not to be required, nor excessive fines imposed,
>
> nor cruel and unusual punishments inflicted" -- Bill of Rights 1689

Sorry, Tim, I meant, <input type="text"> for id of "nameX", not DIV. Thanks.


Evertjan.

unread,
Jun 19, 2013, 4:18:57 AM6/19/13
to
justaguy wrote on 19 jun 2013 in comp.lang.javascript:

> On Tuesday, June 18, 2013 5:44:49 PM UTC-4, Tim Streater wrote:

>> justaguy <lichun...@gmail.com> wrote:

>> > <div id="nameX"></div>
>> > document.getElementById('nameX').value = nm; // line 3

>> I expect a <div> doesn't have a value, it has a textContent.

> Sorry, Tim, I meant, <input type="text"> for id of "nameX", not DIV.

Is it a shortcoming of Javascript,
that it executes the actual code,
and not the code that is ment?

Show your actual and minimalistic code that fails,
and decribe what you mean by fail
by explaining what you expect that code to do.

[please do not quote signatures, and use a real newsreader.]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

JJ

unread,
Jun 19, 2013, 8:27:22 AM6/19/13
to
A DIV element doesn't have a "value" property.
Use "textContent" instead.

justaguy

unread,
Jun 19, 2013, 11:11:29 AM6/19/13
to
On Wednesday, June 19, 2013 4:18:57 AM UTC-4, Evertjan. wrote:
> justaguy wrote on 19 jun 2013 in comp.lang.javascript:
>
>
>
> > On Tuesday, June 18, 2013 5:44:49 PM UTC-4, Tim Streater wrote:
>
>
>
> >> justaguy <lichun...@gmail.com> wrote:
>
>
>
> >> > <div id="nameX"></div>
>
> >> > document.getElementById('nameX').value = nm; // line 3
>
>
>
> >> I expect a <div> doesn't have a value, it has a textContent.
>
>
>
> > Sorry, Tim, I meant, <input type="text"> for id of "nameX", not DIV.
>
>
>
> Is it a shortcoming of Javascript,
>
> that it executes the actual code,
>
> and not the code that is ment?
>
>
>
> Show your actual and minimalistic code that fails,
>
> and decribe what you mean by fail
>
> by explaining what you expect that code to do.
>
>

Thanks for the note. This issue has been resolved, silly me, forgot the sequence of loading...

justaguy

unread,
Jun 19, 2013, 11:12:22 AM6/19/13
to
Resolved, thanks tho. But please check my new question.
Reply all
Reply to author
Forward
0 new messages