Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Help

  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help

    I have completely no idea why this is not working...

    Code:
    <script type="text/javascript">
        var BGS = new Array();
    	
    	BGS[0] = '#00FF00'; /// YELLOW ///
    	BGS[1] = '#FF0000'; ///   RED  ///
    	function changebgr(choice)
    	{
    		document.bgColor = BGS[choice];
    	}
    	
    	function reloadpage()
    	{
    		window.location.reload();
    	}
    	document.write(Date());
    </script>
    Idea's?
    The changebgr function is not working when i do this:

    Code:
    <center><input type="button" value="Red Background" onclick="changebgr(1)"></center>
    <center><input type="button" value="Yellow Background" onclick="changebgr(0)"></center>
    Last edited by Aker15; 03-01-2012 at 08:28 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,561 Times in 2,539 Posts
    Well, it works for me except that #00FF00 is green, not yellow. The (rather pointless) function reloadpage() is not called anywhere.

    Be aware that document.write() statements must be run (as you are doing here) before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

    Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.


    It is your responsibility to die() if necessary….. - PHP Manual
    Last edited by Philip M; 03-01-2012 at 08:37 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm.. I know reloadpage() is not called anywhere, this is because i did not show you the code I used it for... I will read it no need to be a dickhead.

    Thanks

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,561 Times in 2,539 Posts
    Quote Originally Posted by Aker15 View Post
    Hmm.. I know reloadpage() is not called anywhere, this is because i did not show you the code I used it for... I will read it no need to be a dickhead.
    So how much help do you expect to get in this forum in future?

    Code:
    var rude = true;
    var thanks = false;
    if (rude && !thanks) {
    var interestLost = true;
    var moreHelp = 0;
    }

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •