473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 11392
drhowarddrfine
7,435 Expert 4TB
html/css cannot do this. You need to check with javascript.
Nov 21 '07 #2
mzmishra
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.

[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.bgColor="red";
}

//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)*/
</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
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

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

Similar topics

5
by: AFN | last post by:
I'm trying to set a submit button to change text and color when clicked. Like saying "please wait" instead of "submit" and then changing the background color and text color. All works, except for...
2
by: Scott | last post by:
Is it possible to have a button change colour OnClick ? Thanks.
1
by: Rich | last post by:
I have a simple vb2005 app (for testing). It is just a simple winform with one button that brings up a message box. When I invoke the app and click on the button, the message box comes up OK. ...
11
by: free4trample | last post by:
First of all let me say that I know very little about javascript. what i need to do is to write a javascript functin which will change the background color of the table rows based on entrees in...
1
by: shan shah | last post by:
I am working in Java Script. How to chang the background image(picture) of a web page by clicking on a button? Please reply soon. Regards.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.