Click to See Complete Forum and Search --> : prompt with custom bgcolor change


sciguyryan
07-21-2003, 12:27 PM
hi,

does any one know a javascript code to allow users to alter the bgcolor of my page with a prompt on the body load?









any help would be appreciated and greatfully recived

Khalid Ali
07-21-2003, 12:33 PM
Something like this will work,however you will have to make sure that you enter a valid color
<script type="text/javascript">
function ChangeBGColor(){
var color = prompt("PLease enter the color for this page.")
document.getElementsByTagName("body")[0].style.backgroundColor = color;
}
//-->
</script>
</head>
<body onload="ChangeBGColor();">

Nevermore
07-21-2003, 12:33 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Change Page Background onload</title>
<script type="text/javascript">
<!--
function changeBg() {
newCol = prompt("What colour would you like the page's background to be?");
document.body.style.background=newCol;
}
// -->
</script>
</head>
<body onload="changeBg()">

</body>
</html>

Give it a go!

soccer362001
07-21-2003, 12:42 PM
Here is a bg color changer

sciguyryan
07-21-2003, 12:45 PM
thanks that works good!



THANKS A LOT THAT WAS JUST WHAT I NEEDED!