Solved

detect when any text field on my form has changed

Posted on 2012-03-19
4
344 Views
Last Modified: 2012-04-09
I have a form with a whole bunch of text fields on it, I would like to detect when any of those fields have changed so that I can some css properties. Right now I have grey text in the fields explaining what it does, one the user clicks on the field, i want the text to disappear and the color to go back to black. is there any easy way to do this?

TIA :)
0
Comment
Question by:Big Monty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Amar Bardoliwala
ID: 37740826
Hello The_Big_Daddy,

you will need to use onfocus event of textbox as following

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>
 <input name="text1" type="text" id="text1" value="textbox 1" onFocus="this.style.background ='yellow';this.value=''" onBlur="this.style.background='white'">
</p>
<p>
 <input name="text2" type="text" id="text2" value="textbox 2" onFocus="this.style.background = 'yellow'" onBlur="this.style.background='white'">
</p>
</body>
</html>

Open in new window


Hope this will help you.

Thank You.

Amar Bardoliwala
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
ID: 37740901
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
 
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
 
<style type='text/css'>
    .hint { color: grey; background-color: beige; }
.normal { color: black }

  </style>
 


<script type='text/javascript'>//<![CDATA[

jQuery(document).ready(function() {

    $(".hint[hint]").each(function() {
        $(this).val($(this).attr("hint"))
            });

    $(".hint[hint]").focus(function() {
        if ($(this).val() == $(this).attr("hint")) {
            $(this).val("").toggleClass("hint").toggleClass("normal");
        }
    });

    $(".hint[hint]").blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("hint")).toggleClass("hint").toggleClass("normal");
        }
    });




});
//]]>  

</script>


</head>
<body>
  <input class="hint" hint="First Name" />
<input class="hint" hint="Last Name" />

</body>
</html>
0
 
LVL 33

Author Comment

by:Big Monty
ID: 37742558
Proculopsis:

Is there any way to make it so I do not have to add classes to all of my text boxes? there a lot of them and they already have classes assigned to them (not the same name) and would require me to rewrite other jQuery code where I'm selecting certain text boxes by class name
0
 
LVL 33

Author Closing Comment

by:Big Monty
ID: 37824427
not the exact solution I added but pointed me in the right direction
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question