tags:

views:

26

answers:

2

I have made a chatbox in jquery and i want to add the functionality to see "xyz is typing" for this i have written this code

setInterval("typing()", 1000);    
function typing()
{

      var name1= $("#name").val();
      var n=$('#message').val().length();
      if(n>1)
      $('#shout').prepend(name1+'is typing');
}

But its not working. Someoen pls help...

A: 

You shouldn't use "typing()". This will invoke eval() internally. Instead, just use typing.

If you have made a chatbox, you probably want to send to the server via AJAX that the person has typed something.

alex
Actually its a shoutbox and its working fine. Here the url http://algoritmus.in/projects/shoutbox/ . Replaced "Typing()" with typing() bt no use
Kunal Yadav
@Kunal Yeah whoops, don't put the parans at the end :)
alex
A: 

lenght() in not a string function is javascript. You can find length of string by using just string.length. Also change prepend() method to html() method otherwise it will repeat same message [xxx is typing] after each interval.

Here is the updated code

setInterval("typing()", 1000);
function typing()
{
   var name1= $("#name").val();
   var n=$('#message').val().length;
   if(n>1)
     $('#shout').html(name1+' is typing');
} 
Chinmayee