/    Sign up×
Community /Pin to ProfileBookmark

Real-Time document.write?

Hi, I’m kinda new to javascript and I need a solution to my problem.

[code=html]alive=”yes”;
document.write (alive);
function show_confirm()
{
var r=confirm(“Are you sure you want to replace me?”);
if (r==true && alive==”yes” )
{
alert(“Goodbye..”);
displayDate();
alive=”no”;
}
else
{
alert(“Oh, thank you for sparing me!”);
}
}[/code]

Everything works fine, but document.write writes “yes” once, without ever changing it, and I was wondering if there was something that could display the variable’s value in real time. Thanks.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@WolfShadeApr 16.2012 — You're changing the value of the alive variable, but you're not "writing" it. Instead of using document.write, create a div and change the innerHTML to the value of alive. Then, when alive is changed to "no", change the innerHTML to the value of alive.
Copy linkTweet thisAlerts:
@MoltoBeneauthorApr 16.2012 — You're changing the value of the alive variable, but you're not "writing" it. Instead of using document.write, create a div and change the innerHTML to the value of alive. Then, when alive is changed to "no", change the innerHTML to the value of alive.[/QUOTE]

I've tried this and couldn't seem to make it work. Like I said, I'm still kinda new. Anyway I only needed this to show me my variables in real time, for testing purposes. Thanks for your help!
Copy linkTweet thisAlerts:
@nathanwallApr 17.2012 — [code=php]
<!doctype html>
<html>
<head>
<title>example</title>
<script type="text/javascript">
var alive;
var aliveDisplay;

window.onload = function() {
aliveDisplay = document.getElementById('alive-display');
setAlive('yes');
}

function setAlive(value) {
alive = value;
// Use this to update the HTML.
aliveDisplay.innerHTML = alive;
}

function show_confirm() {
var r = confirm("Are you sure you want to replace me?");
if(r == true && alive == "yes") {
alert("Goodbye..");
displayDate();
setAlive('no'); // call this to set alive and update the HTML
} else {
alert("Oh, thank you for sparing me!");
}
}

function displayDate() {
// Do something...
}
</script>
</head>
<body>
<p>Alive value: <span id="alive-display"></span></p>
<div><input type="button" value="show confirm" onclick="show_confirm();" /></div>
</body>
</html>
[/code]
×

Success!

Help @MoltoBene 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,
)...