Click to See Complete Forum and Search --> : Document Property Permanency


S1L3NC3
09-26-2003, 05:42 PM
Can anyone tell me why this script doesnt work? I wrote it up real fast, and its supposed to change the BG to the desired color when the corresponding button is clicked (obviously).
But instead of changing it, it simply flashes it and then returns to white.






<html>
<head>

<script language="javascript">
function backcolor(color)
{
document.bgColor=(color);
}
</script>

</head>
<body>
<div align="center">
<form name="buttons">
<input type="submit" value="White" name="elbutton" onClick="backcolor('white');">
<input type="submit" value="Green" name="elbutton" onClick="backcolor('green');">
<input type="submit" value="Red" name="elbutton" onClick="backcolor('red');">
<input type="submit" value="Blue" name="elbutton" onClick="backcolor('blue');">
<input type="submit" value="Black" name="elbutton" onClick="backcolor('black');">
<input type="submit" value="Purple" name="elbutton" onClick="backcolor('purple');">
</form>
</div>
</body>
</html>

Khalid Ali
09-26-2003, 06:11 PM
thats because your button type is submit,so it changes the bg color and then page is submitted to itself, meaning its being reloaded and then stes the default bg color

change the input type="submit" to
input type="button"

S1L3NC3
09-27-2003, 12:22 AM
Ohhh, I see, thank you very much.