469,294 Members | 1,943 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,294 developers. It's quick & easy.

Change background color on clicking button

158 100+
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.

Expand|Select|Wrap|Line Numbers
  1.   <input style="background-color:green;" TYPE="submit" name="vars" VALUE="Enter">
Nov 20 '07 #1
5 11196
7,435 Expert 4TB
html/css cannot do this. You need to check with javascript.
Nov 21 '07 #2
390 Expert 256MB
write one javascript function for the onclick event
insdie that function write the code for button background change
Nov 21 '07 #3
Death Slaught
1,137 1GB
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.


<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() {

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


<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-->



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

Hope it helps, Thanks, Death
Nov 21 '07 #4
You cant do that in HTML.
Nov 27 '07 #5
Death Slaught
1,137 1GB
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
Nov 27 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.