/    Sign up×
Community /Pin to ProfileBookmark

Using javascript variables in tables…quite a simple one!?

In the <head> section:

var mynumber= 7;
var myanimal = ‘dog’;

[CODE]<td valign=”top” colspan=”2″><textarea name=”message” rows=”4″
wrap=”physical” cols=”50″ onchange=”checkMaxLength(this,1000)”
onkeydown=”checkMaxLength(this,1000)” onkeyup=”checkMaxLength
(this,1000)”>

I NEED TO ENTER TEXT VALUES HERE eg number is 7, animal is a
dog.

</textarea><br><span class=”help” id=”message_help”>Enter up to
characters. 1000. No HTML, asterisks, or quotes. </span><script
type=”text/javascript” language=”JavaScript”>[/CODE]

I tried:

[CODE]<td valign=”top” colspan=”2″><textarea name=”message” rows=”4″
wrap=”physical” cols=”50″ onchange=”checkMaxLength(this,1000)”
onkeydown=”checkMaxLength(this,1000)” onkeyup=”checkMaxLength
(this,1000)”>

number is <SCRIPT>document.write(mynumber)</SCRIPT>,
animal is a <SCRIPT>document.write(‘myanimal’)
</SCRIPT>.

</textarea><br><span class=”help” id=”message_help”>Enter up
to characters. 1000. No HTML, asterisks, or quotes. </span>
<script type=”text/javascript” language=”JavaScript”>[/CODE]

But it didnt work. How do you insert variables into body table text such as this? Sorry to ask such a dumb question. Cheers

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisJul 19.2006 — Anything inside <TEXTAREA> tags is just text, and not interpreted.

You can do this:
<i>
</i>&lt;head&gt;
&lt;script&gt;
var mynumber= 7;
var myanimal = 'dog';
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;textarea name="message" rows="4" wrap="physical" cols="50"&gt;
&lt;/textarea&gt;
&lt;script&gt;
document.getElementById("message").value = "number is " + mynumber + ", animal is a " + myanimal + ".";
&lt;/script&gt;
&lt;/body&gt;
×

Success!

Help @dance621 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...