Hi guys i have tried to create my first plugin but its giving me some odd behaviour.
what im trying to achieve is to put default text in an empty input field and hide it when the field has focus and then show it again if nothing was entered into the field on blur. This i have done pretty easy but the problem start when i use the plugin on more than one input filed per page and it treats all field like the last one in the sequence. so if i focus the first field the text in the last filed in the sequence will disappear ?!?! This is my code for this simple plugin Can anyone see the glaring mistake that i must have made???? function($){ jQuery.fn.showhideinput = function(options) { var defaults = { text: "dd/mm/yyyy" }; var options = $.extend(defaults, options); return this.each(function(index) { obj = $(this); objid = '#'+obj.attr('id'); var inputtext = obj.val(); if (inputtext == ''){ obj.val(options.text); inputtext = options.text; } obj.focus(function () { //alert(objid + ' focus'); if (obj.val() == inputtext){ $(objid).val(''); } }); obj.blur(function () { //alert(objid + ' blur'); if (obj.val() == ''){ $(objid).val(inputtext); } }); }); }; })(jQuery);