?
Solved

trouble hiding DIV tag with javascript

Posted on 2011-05-10
7
Medium Priority
?
316 Views
Last Modified: 2012-06-22
Hi Experts,

For some reason I can't get my code to put a DIV-tag into display=none - mode. I have other similar snippets to work fine, but fail to locate my error.

Any suggestions?
function noticeclose(){
document.getElementById('notice').style.display = 'none';
}

    	<div id="notice" class="examdiv" style="display:block;">

        <font size="+1">Kære musikstuderende.<br>Vis hensyn til hinanden, når i reserverer og følg de gældende retningslinier:<br>
        reserver max 2 timer pr. dag.<br><br>
        Vi har i eksamensperioden også åbnet for, at i kan reservere auditorierne A B og C.<br><br>
        Mvh. administrationen.</font>
        <div style="width:500px; text-align:right;">

        <input name="close" type="button" value="OK" align="right" onclick="noticeclose()" /></div>

    	</div>

Open in new window

0
Comment
Question by:MortenWB
  • 4
  • 3
7 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 35733512
how many objetc do you have with the id (notice) ?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 35733545
work fine for me :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function noticeclose(){
	document.getElementById('notice').style.display = 'none';
}
</script>
</head>

<body>
<div id="notice" class="examdiv" style="display:block;">
	<font size="+1">
    	Kære musikstuderende.<br>Vis hensyn til hinanden, når i reserverer og følg de gældende retningslinier:<br>reserver max 2 timer pr. dag.<br><br>Vi har i eksamensperioden også åbnet for, at i kan reservere auditorierne A B og C.<br><br>Mvh. administrationen.
	</font>
	<div style="width:500px; text-align:right;"><input name="close" type="button" value="OK" align="right" onclick="noticeclose()" /></div>
</div>
</body>
</html>

Open in new window

0
 

Author Comment

by:MortenWB
ID: 35733607
You're fast, leakim971:)

I guess I've got only 1 object - and I can't figure out, why you can get it to work...

I will try to test your code in a seperate page.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:MortenWB
ID: 35733656
Okay - it works allright - so it must be that the DIV displays on every refresh of the original page.

Do you have any suggestions on how one might make the DIV "remember" to stay hidden?
0
 

Author Comment

by:MortenWB
ID: 35733800
... i mean without storing in a database - but using a cookie or something ...
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 1500 total points
ID: 35734029
yes using cookie : http://www.w3schools.com/JS/js_cookies.asp

to save :

setCookie("notice","none"); // or block

and to restore the "state" :

window.onload = function() {
   document.getElementById('notice').style.display = getCookie("notice");
}
0
 

Author Closing Comment

by:MortenWB
ID: 35741865
Thanks for pointing in the right direction:) I had to spend some time understanding the cookiecode at w3scools, though - I'm a slow learner...
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question