How to implement placeholder text on input elements using jQuery?

how can i implement jquery hint text on inputs?

<input class="question_box" title="hint text">

thank:))

+3
source share
8 answers

The first Google result for “ jquery hint text ” is this plugin that looks the way you want.

$('.question_box').hint();
+1
source

HTML5 introduces an attribute placeholderin text fields. Read here: http://www.w3.org/TR/html5/common-input-element-attributes.html#attr-input-placeholder

Live demo: http://jsfiddle.net/simevidas/8mTLY/

Chrome, Safari Opera.
Firefox 4 (, ).
, , IE9 .

+8

EDIT: ok " ", .

$(function() {
    $('.question_box').focus(function() {
        if ($(this).val() == 'Blablabla')
            $(this).val('');
    });

    $('.question_box').blur(function() {
        if($(this).val() == '')
            $(this).val('Blablabla');
    });

}
+2

jquery autocomplete?

0

jQuery 1.5.1 jQuery UI 1.8.9, , jQ UI 1.9: http://jsfiddle.net/JAAulde/XpbGh/1/

Edit: , , , .

0

, helptext placeholder. , - .

 $(' #chkbx_presentkort').on('change', function() {
     if($('#chkbx_presentkort').is(':checked')) {

         $('.lagerstatus #kortet_text').show().val('Skriv din text på kortet').css("color","#666");
         console.log("checked");
         $('.lagerstatus #kortet_text').focusin(function() {
             if($('.lagerstatus #kortet_text').val()== 'Skriv din text på kortet') {
             $('.lagerstatus #kortet_text').val('');
             }
         });
         $('.lagerstatus #kortet_text').focusout(function() {
             if($('.lagerstatus #kortet_text').val() == '') {
             $('.lagerstatus #kortet_text').val('Skriv din text på kortet').css("color","#666");
             }
         });
     }
     else  {
     $('.lagerstatus #kortet_text').hide();
     }
 });
0

There is a similar jQuery plugin called inputHints. I am using the placeholder attribute with javascript for a browser that does not yet support it.

The syntax is very similar to the previously mentioned plugin, but it is available on github, so anyone can help. I have used it with success.

http://robvolk.com/jquery-form-input-hints-plugin/

https://github.com/robvolk/jQuery.InputHints/

0
source

it looks like I'm a little late, but you can just use the placeholder attribute inside your input element. It has been added for some time!

Here is the syntax:

<input placeholder="text">
0
source

All Articles