MattF
MattF

Reputation: 65

why is this function firing twice?

I have this function that fires when a user pastes into the textarea. I have a timed function that fires inside this function so that the function can get the text in the textarea that the user pastes.

My problem is that in safari, this function fires twice each time and I cant work out why.

function Func1(){

    var valu = $('#thoughts').val();
    $(function () { 

        $.post("paste.php", { uid: $('#uid').val(), paste: $('#thoughts').val()},function(data){

            $('#pasteditems').prepend($(data).hide().fadeIn(1300));

        });

    });

    $('#thoughts').css('background','#FFFFFF');
    $('#thoughts').css("color","#AAD1ED");
    $('#thoughts').css("font-size","90px");
    $('#thoughts').val("");    

}

function OnPaste(){

    $('#thoughts').css("font-size","18px");
    $('#thoughts').css('background','#EEEEEE');
    setTimeout("Func1()", 0800);

}

html

<textarea onblur='self.focus' wrap="physical" onpaste="OnPaste ()" id="thoughts" name="thoughts"></textarea>

Upvotes: 2

Views: 1684

Answers (3)

genesis
genesis

Reputation: 50966

Here is another way around

setTimeout(function(){ Func1(); }, 800);

Upvotes: 0

Naftali
Naftali

Reputation: 146302

Try changing the setTimeout Function:

setTimeout(Func1, 0800);

Upvotes: 0

Jordan
Jordan

Reputation: 32522

Try:

setTimeout(Func1, 800);

Safari may be evaluating that function when it reads through that code the first time, since you have the parentheses on it.

Upvotes: 2

Related Questions