Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get default value of an input using jQuery

$(".box_yazi2").each(function () {
    var default_value = this.value;
    $(this).css('color', '#555'); // this could be in the style sheet instead
    $(this).focus(function () {
        if (this.value == default_value) {
            this.value = '';
            $(this).css('color', '#000');
        }
    });
    $(this).blur(function () {
        if (this.value == '') {
            $(this).css('color', '#555');
            this.value = default_value;
        }
    });
});

This function of default value of input doesnt work in FF, but perfectly works in IE and ofcourse the input itself looks like this:

<input type="text" class="box_yazi2" id="konu" name="konu" value="Boş" />
like image 329
Bato Dor Avatar asked Jan 04 '11 08:01

Bato Dor


1 Answers

Just use the defaultValue property:

var default_value = $(this).prop("defaultValue");

Or:

var default_value = this.defaultValue;
like image 157
Salman A Avatar answered Oct 11 '22 06:10

Salman A