I have some bug with the following page: http://jsbin.com/agedu/ Source code with some comments: http://jsbin.com/agedu/edit
The problem is that when typing somethin
The inputdynvalue() function explicitly forces the textbox text when called, even if the textbox is non-empty.
Fix it like so:
(function($) {
$.fn.inputdynvalue = function(options) {
var opts = $.extend({},
$.fn.inputdynvalue.defaults, options);
return this.each(function() {
var hvalue = opts.htext;
switch (opts.htext) {
case 'title':
hvalue = $(this).attr('title');
break;
case 'value':
hvalue = $(this).attr('value');
break;
}
if (this.value === '') {
$(this).attr('value', hvalue).addClass(opts.hclass)
}
$(this).unbind('focus blur').bind('focus',
function() {
if (this.value === this.title) {
this.value = '';
$(this).removeClass(opts.hclass);
}
}).bind('blur',
function() {
if (this.value === '') {
this.value = this.title;
$(this).addClass(opts.hclass);
}
});
});
};
$.fn.inputdynvalue.defaults = {
htext: 'title',
hclass: 'hint'
};
})(jQuery);
The key is the lines:
if (this.value === '') {
$(this).attr('value', hvalue).addClass(opts.hclass)
}
which replace the un-conditional overwrite from before.
The fixed version can be seen at http://jsbin.com/ikipi.