/    Sign up×
Community /Pin to ProfileBookmark

Hi guys, I’m trying to dynamically change some text but for some reason I just can’t….

Here’s what I’m doing:

<head>
<script language=”JavaScript”>
var x = document.getElementById(“resposta”);
x.innerHTML = ‘aaa’;
</script>
</head>
<body>
<div id=”resposta”></div>
</body>

And nothing happens. Any help will be appreciated.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@svidgenApr 04.2009 — The DIV isn't defined yet at the time the script runs. Try one of the following 2 variations:
[code=html]
<head>
<script language="JavaScript">
function xyz() {
var x = document.getElementById("resposta");
x.innerHTML = 'aaa';
}
</script>
</head>

<body onLoad="xyz();">
<div id="resposta"></div>
</body>[/code]

or
[code=html]
<head>
</head>

<body>
<div id="resposta"></div>

<script language="JavaScript">
var x = document.getElementById("resposta");
x.innerHTML = 'aaa';
</script>

</body>[/code]


Also, please post code using the appropriate code tags : )
Copy linkTweet thisAlerts:
@Bruno321authorApr 04.2009 — Thank you very much =)
Copy linkTweet thisAlerts:
@KorApr 04.2009 — The modern tendency and recommendations are to separate the content (HTML), presentation (CSS) and the dynamic behavior (javascript). Furthermore, the document needs a Doctype, otherwise the browser might act in an unpredictable quirks mode while interpreting the CSS and/or javascript codes. And [B]language[/B] is deprecated in favor of [B]type[/B]
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;untitled&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
function xyz() {
var x = document.getElementById("resposta");
x.innerHTML = 'aaa';
}
onload=function(){
xyz();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="resposta"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @Bruno321 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...