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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.