Why this mmediately invoked functions is not working properly
<p>I am using immediately invoked functions pattern, but this is not passing the id</p>

<p>1.When the user clicks on $user, id is passed and the chat window appears</p>

<pre><code>echo "&lt;div class='boxbottom'&gt;&lt;a href='#' onclick=chat_com_one($id);&gt; &gt;$user&lt;/a&gt;&lt;br&gt;&lt;/div&gt;";
</code></pre>

<p>2.Function chatcom_load_one keep checking, if there is any message from the id passed to chatcom_load_one function.</p>

<p>But the problem is that onclick function do passes the id but immediately invoked function did not pass the id to the post function. </p>

<p>Also sending the message is slow?</p>

<p>Please help or suggest any alternate approach, I think error is in the chat_load_one pattern.</p>

<pre><code>function chat_com_one(id) {

    $('#chatcom').show('fast');
    (function chatcom_load_one(id) {
        $.post('sendchat2.php', {
            option: 'chatcom_load_one',
            tocom: id
        }, function (data) {
            $('#chatcom #commid #commidwin').html(data);
            setTimeout(chatcom_load_one(id), 1000);
        });
    }());
    $('#chatcom_send').click(function () {
        var text = document.getElementById('chatcom_text').value;
        $.post('sendchat2.php', {
            option: 'chat_com_send_one',
            text: text,
            tocom: id
        }, f
        function (data) {
            document.getElementById('chatcom_text').value = '';
        });
    });
}
</code></pre>

<p>send function on my server</p>

<pre><code>    if($_REQUEST['option']=='chat_com_send_one'){
    $session=new $session;
    $text=mysqli_real_escape_string($db3-&gt;connection,$_POST['text']);
    $tocom=mysqli_real_escape_string($db3-&gt;connection,$_POST['tocom']);
    $sql=mysqli_query($db3-&gt;connection,"INSERT INTO chat_com(fro,tocom,mesg,time) VALUES ('$session-&gt;userid','$tocom','$text',CURRENT_TIMESTAMP)");
}
</code></pre>
