Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditionally show a button based on Scripting 1

Status
Not open for further replies.

Crackpot21

Technical User
Feb 1, 2006
11
US
I am hoping this is easy, but I have been searching all day with no success. What I am doing is very simple:

I have a page with an iframe and a button to print the contents of the iframe. When the page opens, the browser security chimes in with the "Do you want to ...."

I would like the print button not to show until Javascipt has been enabled.

So this is what I have:
Code:
<script type='text/javascript'>
function show_content() {
document.getElementById("js")<!--.style.display = "none"; -->
}
window.onload = show_content;
</script>

<div id="js" class="printbutton">
<input type="button" value="Print Document" onclick="iPrint(myFrame);" />
</div>

So with this the print button shows no matter what, but I want the button not to appear unless they agree or enable Javascript in IE.
 
script it with a document.write
Code:
<script lanugage="javascript">
document.write"<div id=\"js\" class=\"printbutton\">";
document.write"<input type=\"button\" value=\"Print "Document\" onclick=\"iPrint(myFrame);\" />";
document.write"</div>";
</script>

The above code will ONLY execute if javascript is enabled.

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
I can't remember off the top of my head, but the document.write may need to be document.write("content"); (with the brackets)- I am pretty sure it requires them.

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
You do need brackets. This is what ended up working for me:

Code:
<script lanugage="javascript">
document.write("<div id='js' class='printbutton'>");
document.write("<input type='button' value='Print "Document' onclick='iPrint(myFrame);' />");
document.write("</div>");
</script>

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top