views:

158

answers:

3

I'm trying to show some UI Hints on an ASP.NET MVC 2 app, much like the way they are displayed on the careers site when you edit/fill out your resume: when a form control has focus, a little description of how to enter the required information appears next to it.

Example #1 Example #2

What is the best method to show these suckers...

+1  A: 

jQuery will simplify this, but it could easily be standard JS.

Something like:

$('.controlwithhinttext').focus(function() {
    // show hint
    $('#hint' + $(this).attr('hint_to_show_id')).show();
});

Where the form control has a custom attribute, or just use matching (not identical) IDs.

jezmck
What do you mean by Matching IDs?
hminaya
I meant to use the form control's ID as part of the selector.
jezmck
+4  A: 

Something in the line of:

CSS:

.field{position:relative;}
.field-help{display:none;background:yellow;position:absolute;left:200px;top:0;}

HTML:

<div class="field">
    <input type="text">
    <div class="field-help">Help text</div>
</div>

JQUERY:

$('.field input').bind('focus', function(e) {
    $(e.target).next('.field-help').show();
}).bind('blur', function(e) {
    $(e.target).next('.field-help').hide();
})
David
+3  A: 

Clean your ears!

Err, I mean use the jQuery Qtip plugin: http://craigsworks.com/projects/qtip/

It does 100% of the things your looking for and does it extremely well.

jfar
+1 - thanks for the tip!
spot