BLOG: Web Content Management

Welcome to Oshyn’s Web Content Management Blog where our experts discuss the latest developments and best practices in the Content Management industry with a focus on several leading platforms: Drupal, EPiServer, Jahia, Open Text and Sitecore.

Enterprise Drupal: Form Default values

Enterprise Drupal: Form Default values

Francisco Alvarez... - Tuesday, March 02, 2010

Enterprise Drupal: Webforms, JQuery and Default field values

Almost every website has a Webform, these are used for searches, profile managing or sending emails... We are going to explain an easy way to place a help (default) text on the Form's input fields, using jquery, with a behavior that doesn't interfeer with the desired funcionality for that Webform. On my case I implemented this solution on a Drupal project I was working on, so I'll just add a few notes about this, but the solution can be used everywhere.

The idea is to have a default text (normally with a lighter color) that disappears on focus and appears again onblur if the field is empty.

Below we have an example for you to try:

If you liked it, here's the code:

download demo

/*** Notice the class on the input ***/


/*** This is all the html you need ***/


<input class="default-value" type="text" value="Your text here..." />

/*** You can copy this script to your main js file***/


<script type="text/javascript">

/*** The following variables may be adjusted***/


var active_color = '#000'; // Color of user provided text
var inactive_color = '#ccc'; // Color of default text

$(document).ready(function() {
  $("input.default-value").css("color", inactive_color);
  var default_values = new Array();
  $("input.default-value").focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
      this.style.color = active_color;
    }
    $(this).blur(function() {
      if (this.value == '') {
        this.style.color = inactive_color;
        this.value = default_values[this.id];
      }
    });
  });
});
</script>

Sometimes on Drupal is not that easy to add a class to an input, so I'll explain a really simple way to achieve the desired effect.

  • Go to the page that contains the form (Site building > Pages)
  • Click on edit the page
  • Open the "Content" section
  • Find the content portion that contains your form
  • Click the upper right icon and select the "CSS properties" option
  • Set your own ID or Class
  • Modify your javascript and add this class/id to the selectors (eg: input.default-value, #my-id).


I found the original post at http://webdeveloper.beforeseven.com/jquery/default-text-field-value-disappears-focus, the author of the code is Rob Schmitt. There's also a "no jquery" version of it.

ajax rotator
Recent Posts

RSS feeds
Tag cloud
open text delivery server geographical foursquare search suggest cms whitepaper reddot cms ASP.NET MVC optimization LiveServer jquery, jquery plugin Jahia google php5 facebook data access project management ASP.NET reddot white paper Navigation LS ipc profile tab content management los angeles web3.0 google analytics content mangement sitecore devices VPP JSR-168 inbound marketing E-commerce EPiServer web marketing for dummies code design social network rdbs google maps jahia cms friendly url concrete5 dynament search engine cookie-free domain Drupal drools web marketing asp GIS facebook app, OS 3.0, three20 facebook developers templating fbml .net memcache command line linux call to action content authors plugin Web development marketing ajax push multisite cms los angeles, content management los angeles, web development los angeles, website design los angeles, web design los angeles, sitecore meetup, sitecore user group frontend optimization WCM Design Patterns tuckey design twitter web2.0 Delivery Server theming Database Maven performance Solr webcomponent consulting Business Users CTA HubSpot Active Directory new sites OO Development Actionscript 3 Flash tuning web evolution mashups mashup mashware Sitecore Active Directory thoughts missing images Ubercart sitecore oms development java sitecore online marketing suite, online marketing suite web design los angeles icefaces iphone GSA sitecore ECM campaigns VB location web development los angeles oshyn Sharepoint Visual Basic sitecore email campaign manager html lead management javascript release management CMS usability content management white paper SMM web services open text management server opentext industry challenges social 2.0 tools open-source VS2010 geo mysql open source ubuntu APC portlets drush RFP licencing IIS reddot cms higher education postgis reddot higher education scalability Live Server google search appliance higher education software design architecture css online marketing cloud sitecore layout IT Investment web design jquery ajax cluster boost EPiServer Active Directory print Velocity content authoring Acquia open text liveserver CMS wcm lucene google appEngine multilingual modules sitecore meetup Visual Studio reddot deployment keywords content management whitepaper design patterns cms los angeles open text cms ui jahia wcm profile box oms target dynament template design cms white paper SEO website design los angeles social media presentation layer editing content Sitecore content management systems integration jsp cloud computing web content management configuration management keyword selection CMS Training communicating open text web solutions enterprise mobile Ubuntu Server liferay MVC php redundant database structure patterns sales 2.0 open text Dynamic Data reddot whitepaper AS3 spatial url sitecore user group CRM Marketing Automation LDAP lead generation management portal
2010 Copyright Oshyn. All rights reserved.