Results 1 to 7 of 7

Thread: help needed...

  1. #1
    Join Date
    Sep 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help needed...

    Currently i am trying to figure out how to change background color of a document and the text color with the click of a button, but so far i can only get the background color to change :\ heres what im using...

    Code:
    <html><head><title>TEST</title></head>
    
    <body text="black">
    <h2>Testing...</h2>
    <FORM> 
    <INPUT type="button" value="Change bg and text color" name="button3" 
    
    onClick="document.bgColor='yellow'" onmousedown="document.text='red'"> 
    </FORM>
    </font>
    </html>
    any ideas on how to get the text color to change when the button is clicked?

  2. #2
    Join Date
    Dec 2005
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This should do it:
    onClick="document.bgColor = 'yellow'; document.fgColor='red';"

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, no it shouldn't.
    Code:
    <html>
      <head>
        <title>TEST</title>
        <style type="text/css">
          body {
            color: black;
            /* always specify a background colour when you specify a foreground colour. */
            background-color: white;
          }
        </style>
      </head>
      <body>
        <h2>Testing...</h2>
          <form action=""> <!-- The "action" attribute is required. -->
            <input
              type="button"
              value="Change BG and text color"
              name="button3"
              onclick="
                document.body.style.backgroundColor='yellow';
                // There is no need to use more than one event for multiple statements.
                // Seperate them with semicolons (;) and/or linebreaks.
                document.body.style.color='red';
              "
            /> 
        </form>
      </font>
    </html>
    I suggest you run your code through a validator. I also recently gave some advice about laying out your code nicely, which I suggest you follow.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Sep 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    whats it really matter though if the source is validated and indented? as long as a code works fine in internet explorer and firefox im satisfied

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I was surprised that this:

    onClick="document.bgColor = 'yellow'; document.fgColor='red';"

    actually worked. Never heard of fgColor before, learn something old every day. This really doesn't seem as though it would be very cross browser friendly. But, sometimes the oldest methods (I'm assuming this is an old method) are the best when it comes to that. What browsers won't this work on, Twey?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I think it's probably rather cross-browser friendly; bgColor at least I seem to remember being around before CSS was in wide usage, and if it's now still supported, it's probably fairly widely-instated. However, it is not, by any stretch of the imagination, forward-compatible, and so should be avoided at all costs (except perhaps as a safety-net for older browsers). Not being backwards-compatible is bad; not being forwards-compatible is worse.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    Never heard of fgColor before, learn something old every day.
    There are several colour-related properties on the document object, however they were all deprecated for properties on the body element, which were in turn deprecated for CSS properties.

    Mike

Bookmarks

Posting Permissions

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