473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change background colour of form input field as soon as thevalue is changed?

Hi

How do I change the background colour of an input box in a form as soon
as the value is changed? Also the background should revert back to it's
original colour if the user decides that they do not want to make any
changes and hence retype back the orginial value.

I do not want the background to change after the user has moved to the
next form field but as soon as the value has been changed.

I am not sure how to start.

All your help will be appreciated.

Bundy

Oct 1 '06 #1
3 17321


Bundy wrote:

How do I change the background colour of an input box in a form as soon
as the value is changed? Also the background should revert back to it's
original colour if the user decides that they do not want to make any
changes and hence retype back the orginial value.

I do not want the background to change after the user has moved to the
next form field but as soon as the value has been changed.

You could use an onkeypress and/or onkeyup event handler and compare
this.value to this.defaultVal ue. Then you can set
this.style.back groundColor as needed:

function setColor (control, color) {
if (control.style) {
if (control.value != control.default Value) {
control.style.b ackgroundColor = color;
}
else {
control.style.b ackgroundColor = '';
}
}
}

<input type="text"
value="initial value"
onkeypress="set Color(this, 'lightblue');"
name="inputName ">
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 1 '06 #2
Here's an idea...

You'd could capture the onBlur event (when the user LEAVES the input
field), and then check to see what the current value of that field is.
Compare it to the "default" value (the value you want it to be), and if
it's not a match, change the background color of the input field.

Bundy wrote:
Hi

How do I change the background colour of an input box in a form as soon
as the value is changed? Also the background should revert back to it's
original colour if the user decides that they do not want to make any
changes and hence retype back the orginial value.

I do not want the background to change after the user has moved to the
next form field but as soon as the value has been changed.

I am not sure how to start.

All your help will be appreciated.

Bundy
Oct 1 '06 #3
Thank you.

I have slightly modified the function provided by Martin Honnen and now
it works perfectly as I want it.

It was the onkeypress and onkeyup event handlers that I needed.

Regards

Bundy
Oct 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10922
by: Wim Roffal | last post by:
Is it possible to use javascript to change the name of a field in a form? Thanks, Wim
1
6140
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there are no instructions on how to make checkboxes and radio buttons required. I've tried adding these to my form, but I'm having no luck. Anyone know how to add radio buttons and checkboxes using the existing code mentioned on the url? Thank you!
4
1817
by: Semi Head | last post by:
Hello folks, I'm looking for a script to validate a specific number value in a standard form input field. An example would be, if someone enters a number into a form input, I want the script to validate it and give an alert if that the number exceeds the set script value. Like if the script value is set for 3000 and the number 3002 is entered, I want an alert to pop and give a warning, BTW - This script must be generic enough to work...
10
1749
by: yawnmoth | last post by:
i've written some javascript code that i believe should set a form variable to a certain value, depending on what the user clicks on. unfortunately, it isn't working. here's the url: http://www.frostjedi.com/terra/scripts/graemlin3.html clicking in the color palette thing and then clicking the submit button reveals that the form variable named color isn't being set. if you look at the javascript source, you'll see that i'm atleast...
3
4744
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
5
2370
by: Garry Jones | last post by:
I have a form that I have designed with colors. I am using php code to color it depending upon other values. On my pc the colors are ok. From a friends pc every field with the word email in had a different colour. When I change the spelling of "email" to "emial" the colours displayed on his pc revert back to the colours I have set. We are running identical versions of windows and msie. Except mine is the Swedish version and he has the...
4
45842
by: Bosconian | last post by:
I've been fighting with this for an hour. My form contains a hidden input with the value initially set to "". When a user clicks on the link, a function is called that updates the hidden form value and submits the form. Unfortunately this generates an error which states the form object is undefined.
3
2411
by: helraizer1 | last post by:
Hi all, On one page of my site I have a form (code below) with an input textbox with the id "message". You type in your message in this field (as the id suggests) and depending on an option in a select element (still part of the form) the text of 'message box' changes to that colour. form: <form id="input" method="post" action="<?php echo $PHP_SELF; ?>"> Name: <input id="username" type="text" name="username"...
4
3048
by: wizardry | last post by:
hello - i've created a form that has multiple inserts. it inserts the data fine if i manually parse the data to it but when i use the form to test the inserts it errors out. it errors out at the title/comments table. the 2 tables before are inserted fine. i've used echo $_post variable and the variable is their. but its not being inserted into the database. ...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7320
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.