JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 20th, 2012, 11:19 AM
msmith29063 msmith29063 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 202 msmith29063 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 26 m 46 sec
Reputation Power: 10
Question JQuery: Need Help w/ Show or Hide on Form Field Click

I've got a jQuery script I use for hiding/showing default values in small forms:

Code:
$("#contactForm .textField").focus(function() {
	if (!default_values[this.id]) {
		default_values[this.id] = this.value;
	}
	if (this.value == default_values[this.id]) {
		this.value = '';
	}
	$(this).blur(function() {
		if (this.value == '') {
			this.value = default_values[this.id];
		}
	});
});


The issue is that I need to use this script on multiple fields (with the same CSS class) within the same form. What syntax changes need to be made? Right now -- this script will work for the first field you click in -- but won't work for the other fields in the same form.

Thank you for your help.

Reply With Quote
  #2  
Old November 20th, 2012, 02:02 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,833 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 20 h 52 m 20 sec
Reputation Power: 4192
Did you supply the appropriate key/value pairs for all of the fields in the "default_values" object?

Have you considered using the new HTML5 placeholder attribute? You could use a script to add support for older browsers.

http://robertnyman.com/2010/06/17/a...ve-enhancement/
http://css.dzone.com/news/adding-html5-placeholder
https://github.com/marcgg/Simple-Placeholder
http://www.jacklmoore.com/notes/form-placeholder-text
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > JQuery: Need Help w/ Show or Hide on Form Field Click

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap