hii this my code.the problem is i'm changing the background color for an header using on click function in javascript.but wen i did page refreshing the default background color is appearing.i want to dislay the changed background color of that header wen once on click function is done. please help me.

<html
<head>
<script type="javascript">
function background()
{
var x= document.getElementById('d1').value;
if(x !='NULL')
{
document.getElementById('h1').style.background='green';
}
}
</script>
</head>
<body>
<form action"1.php" Method="post">
<h1 id="h1" style="background:black"> Hi How r U frends </h1>
<input type="radio" value="changebg" name="d1" id="d1" on click="background()">display Message
<input type="radio" value="changebg" name="d1" id="d1" on click="background()">display Message
</form>
</body>
</html>

here the default background color of h1 is balck.by clicking the radio button the background was  
changing into green.i want to display the h1 with green back ground upto session ends & even after 
page refreshing.help me......
many thanx to all
Member Avatar for stbuchok

use a cookie to hold the information about what the background colour is and use it if it is available on page load. You can also use localStorage or a database (indexdb or websql) for the same purposes.

Member Avatar for diafol

If you're using server-side code, you could store the info in a session (or cookie).

hi diafol..can u please wrote a piece of code for how to store & retrive the data from cookies.

Member Avatar for diafol

No. That's down to you. Research and test. Then come back with what you've tried.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.