gevans Posted July 30, 2009 Share Posted July 30, 2009 Hey guys, I've written a little javascript (using the jquery library) to do some simple text removes on input and textarea elements. The code for the textarea is as follow; var value_array = new Array(); $(document).ready(function() { $("textarea").focus(function() { if($(this).html() == value_array[$(this).attr('name')]) { $(this).html(''); } }); $("textarea").blur(function() { if($(this).html() == '') { $(this).html(value_array[$(this).attr('name')]); } }); }); All it does is on page ready, assign the innerHtml value of all textarea to an array, indexed by their name attribute. focusing on the textarea will remove the text if it is the same as the stored text. blur will put the original text back in place if innerHtml is empty, otherwise it leaves the new content. This all works wonderfully appart from in safari where onblur it always puts the original text back in place. Any idea? Cheers Link to comment https://forums.phpfreaks.com/topic/168184-solved-safari-doesnt-like-my-javascript/ Share on other sites More sharing options...
rhodesa Posted July 30, 2009 Share Posted July 30, 2009 instead of $(this).html() try $(this).val() Link to comment https://forums.phpfreaks.com/topic/168184-solved-safari-doesnt-like-my-javascript/#findComment-887066 Share on other sites More sharing options...
gevans Posted July 31, 2009 Author Share Posted July 31, 2009 I already use .val() for the input fields. It doesn't work with textareas as it doesnm't actually set a value originally, it's just considered innerHtml. Link to comment https://forums.phpfreaks.com/topic/168184-solved-safari-doesnt-like-my-javascript/#findComment-887508 Share on other sites More sharing options...
gevans Posted July 31, 2009 Author Share Posted July 31, 2009 Just thought, it should work with taking the innerHtml at the beggining, and doing the checks against the val()... $("textarea").focus(function() { if($(this).val() == value_array[$(this).attr('name')]) { $(this).html(''); }});$("textarea").blur(function() { if($(this).val() == '') { $(this).html(value_array[$(this).attr('name')]); }}); Link to comment https://forums.phpfreaks.com/topic/168184-solved-safari-doesnt-like-my-javascript/#findComment-887510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.