0

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
3
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by diafol
0

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.

0

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

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.