Change background color on clicking button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kardon33
    New Member
    • May 2007
    • 158

    Change background color on clicking button

    I need to make an input button for a form i have created in html, But what i need to do is when the button is clicked it turns the background to green or whatever and when clicked again it turns back to the color before.

    Heres what i have but that bg color stays the same.

    Code:
      <input style="background-color:green;" TYPE="submit" name="vars" VALUE="Enter">
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    html/css cannot do this. You need to check with javascript.

    Comment

    • mzmishra
      Recognized Expert Contributor
      • Aug 2007
      • 390

      #3
      write one javascript function for the onclick event
      insdie that function write the code for button background change

      Comment

      • Death Slaught
        Top Contributor
        • Aug 2007
        • 1137

        #4
        If you post this in the JavaScript forum they're going to give you same thing I am now, so i'll save you a post.

        [HTML]<html>

        <head>
        <script type="text/javascript">
        //JavaScript can go in either the head or body elements
        //You use the script tag to tell the browser you are using script
        //The type attribute tells the browser what type of langauge it is

        function change() {
        document.bgColo r="red";
        }

        //This generates a function, and that functions name is change
        /*document.bgCol or tells the browser that what you're changing is in the document of the page, and that your changing the background color (bgColor)*/
        </script>
        </head>

        <body>
        <form>

        <input type="button" onClick="change ()" value="Change" />
        <!-- onClick tells the browser that when this is clicked you want this to happen, in this case you want to execute the function change-->

        </form>
        </body>

        </html>[/HTML]

        If you have any more questions on this please ask them in the JavaScript forum.

        Hope it helps, Thanks, Death

        Comment

        • nirchuk
          New Member
          • Nov 2007
          • 4

          #5
          You cant do that in HTML.

          Comment

          • Death Slaught
            Top Contributor
            • Aug 2007
            • 1137

            #6
            Originally posted by nirchuk
            You cant do that in HTML.
            I believe that drhowarddrfine already said that, please read others post as well as the origonal posters.

            Furthermore I already gave him the answer so unless there is a problem there, there's no need to continue this thread.

            Thanks, Death

            Comment

            Working...