...

View Full Version : A href="#" doesn't work in document.write



huyden181
06-20-2012, 10:38 AM
I want to show and hide div but i have a problem




<script type="text/javascript">
function showstuff(boxid){
document.getElementById(boxid).style.visibility="visible";
}

function hidestuff(boxid){
document.getElementById(boxid).style.visibility="hidden";
}
</script>

<div id="click_text_and_hide_me" style="visibility: visible">
<a href="#" onclick="showstuff('selectionA');hidestuff('click_text_and_hide_me')">A</a><br>
<a href="#" onclick="showstuff('selectionB');hidestuff('click_text_and_hide_me')">B</a></div>
<div id="solution" style="visibility: hidden">Here is the solution</div>
<div id="selectionA" style="visibility: hidden">
You clicked the selection A<br>

<script type="text/javascript">
var x="variable_inputed";
if( x === "variable_compare"){
document.write("<b>That's Right</b>");
}else{
document.write("<b>False</b><br><a href="#" onclick="showstuff('solution')">Click here to see the solution</a>);

}

</script>
</div>
<==div selentionB is the same==>


When I use

<a href="#" onclick="showstuff('solution')">Click here to see the solution</a>
in document.write in the "IF ELSE" command. It doesn't work. so in "ELSE", How do I have to do with my aim? ( show div "solution" )

Richter
06-20-2012, 10:56 AM
document.write("<b>False</b><br><a href="#" onclick="showstuff('solution')">Click here to see the solution</a>);

You can see it's mismatch and wrong in many way. It should be like this.

document.write("<b>False<\/b><br><a href=\"#\" onclick=\"showstuff(\'solution\')\">Click here to see the solution<\/a>");

Philip M
06-20-2012, 12:52 PM
<script type="text/javascript">
var x="variable_inputed";
if( x === "variable_compare"){
document.write("<b>That's Right</b>");
}else{
document.write("<b>False</b><br><a href="#" onclick="showstuff('solution')">Click here to see the solution</a>);

}

</script>
</div>
<==div selentionB is the same==>
[/CODE]


This is meanigless. If var x="variable_inputed"; x cannot be equal to "variable_compare".

document.write() is in effect obsolete. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum