/    Sign up×
Community /Pin to ProfileBookmark

newb – dynamically reveal content … ?

I have included a javascript in my index.html which will display a section of code based on a variable being set to “yes”. Its default setting is “no”.

[code] if (showcode_1 == “yes”) {

document.write(‘<br /><br />’);
etc etc…
}
[/code]

However, there’s a <form> button which I can press on index.html which onClick sets showcode=”yes”.
Obviously at that point the document has been formed etc so setting showcode_1=”yes” at that point won’t do anything.

Is there anyway to let that code display once showcode_1 has been set to “yes” dynamically as soon as I press that button?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JeroenHoekstraAug 10.2010 — Try this...

Head:

[CODE]
<script type="text/javascript">
<!--
var code_1 = "<p></p>";

function showCode(id, code){
if (document.getElementById(id).innerText == "" || document.getElementById(id).textContent == "") {
document.getElementById(id).innerText = code;
document.getElementById(id).textContent = code;
}
else{
document.getElementById(id).innerText = "";
document.getElementById(id).textContent = "";
}
}
-->
</script>
[/CODE]


Body:
[CODE]
<div id="codeSection_1" style="border: 1px inset #000000; padding: 2px; margin-bottom: 10px;"></div>
<button onclick="showCode('codeSection_1', code_1);">Show code</button>
[/CODE]


Hope this helps!
Copy linkTweet thisAlerts:
@BansawauthorAug 11.2010 — thanks!
×

Success!

Help @Bansaw 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.13,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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