9. June 2008 by Janko in Tutorials | tags: ,

In my previous article "Labels in form layouts" I wrote about how I have implemented "underlined labels" on web application forms. However, due to complexity of web appications I developed I often needed to find a way to focus a user on a current context. When I discovered jQuery I decided to use it because of its powerful features.

Since the forms were often very complex and had (too much I would say) controls on them, I needed to focus a user's attention on the current context. I first thought to highlight the current row.

In this example I'll show you what I tried to do.

Row highlighting

The image above shows that whatever user do, current row will be highlighted. The html markup for the example above will look like this:

    <h3>Sample web form</h3>
<div class="content">
<div class="row">
<div class="left">First name</div>
<div class="right"><input name="Text1" type="text" class="text" /></div>
<div class="clear"></div>
</div>
<div class="row">
<div class="left">Last name</div>
<div class="right"><input name="Text1" type="text" class="text" /></div>
<div class="clear"></div>
</div>
<div class="row">
<div class="left">Email</div>
<div class="right"><input name="Text1" type="text" class="text" /></div>
<div class="clear"></div>
</div>
<div class="row">
<div class="left">Password</div>
<div class="right"><input name="Text1" type="text" class="text" /></div>
<div class="clear"></div>
</div>
</div>
<hr />
<!- Other rows here -->
</div>
<input name="Button1" type="button" value="Do some action" />

And CSS classes are pretty simple as well:

body{
font-family:Arial, Helvetica, sans-serif;
font-size: 13px;
}
.content{
padding:10px;
width:370px
}
.left{
width:150px;
float:left;
padding:7px 0px 0px 7px;
min-height:24px;
}
.right{
width:200px;
float:left;
padding:5px;
min-height:24px;
}
.clear{
float:none;
clear:both;
height:0px;
}
.row{
background-color:none;
display:block;
min-height:32px;
}
.text{
width:190px;
}
.ruler{
width:400px; border-bottom:dashed 1px #dcdcdc;
}
tr:focus{
background-color:#fcfcf0;
}
td{
vertical-align:top;
}
.over{
background-color:#f0f0f0;
}
.out{
background-color:none;
}

Each "row" consists of two div's, one for a label and other for an input field(s). So what we tried to achieve it to highlight a current row whenever user click on any element inside that row. It could be an input field or a label.

Now let's see the simplicity of jQuery:

$(document).ready(function()
{
$('.left, .content input, .content textarea, .content select').focus(function(){
$(this).parents('.row').addClass("over");
}).blur(function(){
$(this).parents('.row').removeClass("over");
});
});

Whenever an input, textarea, select, or element that has "left" CSS class get focus, append "over" CSS class to all parents that have "row" CSS class. Also, whenever an input, textarea, select, or element that has "left" CSS class lose focus, remove "over" CSS class from all parents that have "row" CSS class.

This was very interesting and extremely simple solution, but in a forms more complex that the one in the example above it just didn't make much improvement. What I wanted actually was to highlight a group of related fields. Thanks to jQuery it was very easy to change the rules:

$(document).ready(function()
{
$('.left, .content input, .content textarea, .content select').focus(function(){
$(this).parents('.content').addClass("over");
}).blur(function(){
$(this).parents('.content').removeClass("over");
});
});

Note that the only change is parents() target. Instead of changing only parent row, we can highlight a whole group of rows. Each div that has "content" CSS class will be highlighted whenever any of his children get focus and vice versa.

And this is what it looks like in the end:

highlight group

In very complex web forms this enables users to focus only on a current action. By using attractive color schema and jQuery animations, this can be even more interesting.

You can see the demo here: http://www.jankoatwarpspeed.com/examples/ContextHighlighting/

Conclusion

You saw how you can easily improve the user experience by highlighting the current context. You also saw that it is extremely easy to do it by using jQuery. If you didn't use jQuery I can only suggest you to visit jQuery official website and download the library. There, you can find the documentation, examples and other stuff as well.

kick it on DotNetKicks.com

Comments

Pingbacks and trackbacks

  1. Trackback from DotNetKicks.com Building a better web forms: Context highlighting using jQuery
  2. Trackback from Design Bump Story on DesignBump.com
  3. Pingback from jesusyepes.com Resaltado de campos en los formularios con Jquery | Uno de los otros
  4. Pingback from fuzzlinks.com FuzzLinks.com » Building a better web forms: Context highlighting using jQuery
  5. Pingback from blog.bruno.locaweb.com.br rascunho » Blog Archive » links for 2008-06-29
  6. Pingback from toonz.wordpress.com links for 2008-06-29 « toonz
  7. Pingback from blog.clsoporte.co.cc Información de Tecnologías»Archivo del blog » Siguiendo con jQuery
  8. Pingback from mandarine.wordpress.com links for 2008-06-30 « Mandarine
  9. Pingback from a.morelyrics.co.uk A » Blog Archive » Building a better web forms: Context highlighting using jQuery
  10. Pingback from ajaxsite.net Ajaxsite » Blog Archive » Jquery-Context highlighting
  11. Pingback from sysolution.wordpress.com links for 2008-08-06 [delicious.com] « sySolution
  12. Pingback from cnet.ro Janko ÅŸi aspectul formularelor web | CNET.ro
  13. Pingback from noupe.com Form Elements: 40+ CSS/JS Styling and Functionality Techniques
  14. Pingback from anieto2k.com Mejora los elementos de tus formularios con CSS/JS | aNieto2K
  15. Pingback from webdesignjunkies.com Form elements 40 css js styling and functionality techniques
  16. Pingback from ricoterox.com.ar Mejora los elementos de tus formularios con CSS/JS » Ricotero's Blog
  17. Pingback from canturko.com 40 Adet Css Template ve EÄŸitimi |
  18. Pingback from thetoptenme.wordpress.com “The Complete Guide” for jQuery Developer- Reblog « Dynamic Disruption
  19. Pingback from xinsync.xju.edu.cn 冰山上的播客 » Blog Archive » 表单元素:40个CSS/JS风格和功能技术处理
  20. Pingback from edgargranados.es 40 Elementos interesantes para tus formularios | Edgar Granados
  21. Trackback from analyzer 表单元素:40个CSS/JS风格和功能技术处理
  22. Pingback from 1clickdownload.net Free Download Software-Jquery-Context highlighting
  23. Pingback from blogs.vinuthomas.com Focus - Improving Form usability using jQuery | VT's Tech Blog
  24. Pingback from tutorialo.com Building a better web forms: Context highlighting using jQuery
  25. Pingback from sandeepmundra.com S A N D E E P [ I N D I A N I C ] » Blog Archive » Form Elements: 40+ CSS/JS Styling and Functionality Techniques
  26. Pingback from yogodoshi.com O Melhor da Semana - XXVI - Blog do yogodoshi - Tecnologia, Blogosfera, web 2.0 e Humor é claro!
  27. Pingback from balearsinnovacio.com Recopilatorio actualizado capa de usuario » Innova Desarrollos informáticos
  28. Pingback from nettuts.com 10 Smart Javascript Techniques to Improve Your UI - NETTUTS
  29. Pingback from caphrim.net Tims Blog » Blog Archive » I understand
  30. Pingback from hmvrulz.wordpress.com Form Elements: 40+ CSS/JS Styling and Functionality Techniques « HMV.co.in
  31. Pingback from blog.expertzweb.com Improve Your User Interface With JavaScript 10 Examples at expertzweb
  32. Pingback from blog.miraclestudios.us MiracleStudios.us Blog » Blog Archive » Improve Your User Interface With JavaScript 10 Examples
  33. Trackback from Morning Break Janko At Warp Speed reached 1000+ subscribers!
  34. Pingback from feo.yi.org FeoLab » Blog Archive » 40+ CSS/JS 樣式小工具
  35. Pingback from sulvision.com Form Elements: 40+ CSS/JS Styling and Functionality Techniques | Css Edge
  36. Pingback from poshwebsolutions.blog.co.in Improve Your User Interface With JavaScript 10 Examples | Web Design Company India: Posh Web Solutions
  37. Pingback from poshwebsolutions.wordpress.com Improve Your User Interface With JavaScript 10 Examples « Web Design Company in India: Posh Web Solutions
  38. Pingback from poshwebsolutions.wordpress.com Improve Your User Interface With JavaScript 10 Examples « Web Design Company in India: Posh Web Solutions
  39. Pingback from boostmycode.com Boost My Code » CSS Forms Javascript Usability jQuery » Highlight a row in a form
  40. Pingback from spoonfeddesign.com 100 Best JavaScript Resources | Spoonfed Design
  41. Pingback from fs2yo.cn 100个最佳的JavaScript资源(21~40) | 寂静之声
  42. Pingback from wpconfig.com Wordpress Blog Services - Beautiful Forms - Design, Style, &amp; make it work with PHP &amp; Ajax
  43. Pingback from invisibile.org Beautiful Forms - Design, Style, & make it work with PHP & Ajax
  44. Pingback from ajaxupdates.com Jquery-Context highlighting
  45. Pingback from reader.misrit.org 10 AJAX-based & PHP WebMail Clients For a Great User Experience | Feed Reader (Beta)
  46. Pingback from angelspicks.com Angels Picks » Blog Archive » Beautiful Forms - Design, Style, & make it work with PHP & Ajax
  47. Pingback from e-szablony.eu Beautiful Forms - Design, Style, & make it work with PHP & Ajax | e-szablony.eu
  48. Pingback from neurosoftware.ro Beautiful Forms - Design, Style, & make it work with PHP & Ajax | Programming Blog
  49. Pingback from blog.expertzweb.com Improve Your User Interface With JavaScript 10 Examples at Expertz
  50. Pingback from keanhui.com Beautiful Forms - Design,Style, & make it work with PHP & Ajax | KeanHuiâ„¢ - Creative Resources and Inspirations
  51. Pingback from iwanna.cn 表单元素:40个CSS/JS风格和功能技术处理 | 我想网
  52. Pingback from hiredgunscreative.com A Web Developer’s Bookmarks « Hired Guns Creative
  53. Pingback from my2tech.com Form Elements: 40+ CSS/JS Styling and Functionality Techniques | www.my2tech.com
  54. Pingback from 4dump.com Form Elements: 40+ CSS/JS Styling and Functionality Techniques | 4dump.com
  55. Pingback from answerspluto.com list of urls 4 « Answers Pluto
  56. Pingback from queduros.com Que Duros.com!!! » Estilos CSS Avanzados (Inglés)
  57. Pingback from nethobo.com 100个最佳的JavaScript资源(21~40) - Hobo
  58. Pingback from millionaire.websitesuperhero.com Building a better web forms: Context highlighting using jQuery
  59. Pingback from ajaxupdates.com Building a better web forms : Context highlighting using jQuery
  60. Pingback from 1stwebdesigner.com 51 Form Element Resources and Tutorials Using CSS And Javascript | Graphic and Web Design Blog -Resources And Tutorials
  61. Pingback from huibit05.com 51 Form Element Resources and Tutorials Using CSS And Javascript | huibit05.com
  62. Pingback from downrex.com Form Elements: 40+ CSS/JS Styling and Functionality Techniques | Downrex
  63. Pingback from erkcm.wordpress.com Some Useful Jquery Applications for your Web « Er.Krushna Chandra Muni :: Professional Web Developer,Website Design Orissa,Website Design Bhubaneswar,Indian Freelancer,website design india
  64. Pingback from pc-aras.com 51 Form Element Resources and Tutorials Using CSS And Javascript | pc-aras
  65. Pingback from neurosoftware.ro 51 Form Element Resources and Tutorials Using CSS And Javascript - Programming Blog
  66. Pingback from vndeveloper.com 10 Smart Javascript Techniques to Improve Your UI | Vietnam Developer Club
  67. Pingback from garcon.cz Link Backup from Delicious.com » Blog Archive » links for 2009-11-01
  68. Pingback from theme-center.com CSS/JS Styling and Functionality Techniques | Theme Center
  69. Pingback from denbagus.net 5 nice resources and tutorials form with jquery | denbagus blog

Add comment

   
        Country flag
biuquote
Loading