Jump to content

[SOLVED] Safari doesn't like my javascript?


gevans

Recommended Posts

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

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')]);	}});

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.