PDA

View Full Version : my HTML prompt isnt working



catfreak54
Jul 15th, 2009, 11:14 PM
it works when i put it on my website in the editor but not when i go TO my website.

<script> var theBGColor = prompt('Choose your background color');
var theFontColor = prompt('Choose your text color');
document.body.style.background = theBGColor;
document.body.style.color = theFontColor;

this dosent work ether

<script> var name = window.prompt("What= is your name?");document.write("Hello " + name + ".Welcome to my site. I hope you find what your looking for.");
i embeded javascript in HTML so this might be the rong catagory

catfreak54
Jul 17th, 2009, 07:42 PM
can any 1 help me?

ckeyrouz
Jul 17th, 2009, 07:50 PM
I think you are calling your method inline before the page to be loaded:
you should wrap your code in a function and then call it on a certain event:


<script type="text/javascript">

function changeBgColor()
{
var theBGColor = prompt('Choose your background color');
var theFontColor = prompt('Choose your text color');
document.body.style.background = theBGColor;
document.body.style.color = theFontColor;
}
</script>

I called onload you can call it on any button click:
Anyway this is how I called it:

<body onload="changeBgColor()">