php - single function in javascript called multiple times -
in below code i'm running loop. within have 4 links , have written onclick event. if click on particular link having user_id function myfunction
, there i'm calling function refreshid(session_to_user)
. first time click event working fine. if click on link 2 other functions start running vice versa.
my requirement according link click function refreshid(session_to_user)
should work. while clicking first should work first user_id. if clicked second link first user_id should suspended second link user_id should used. please me.
for loop() { <a id='some' name='some' onclick='myfunction(".$result['user_id'].")'></a> }
function refreshid(session_to_user) { setinterval(function() $('.chat-box').load("<?php echo base_url()."users/message/refresh_div/"; ?>" + session_to_user); }, 10000); } function myfunction(user_id) { var session_to_user = user_id; refreshid(session_to_user); }
you need clear interval on each call:-
var interval; function refreshid(session_to_user) { if(interval) clearinterval(interval); interval = setinterval(function() $('.chat-box').load("<?php echo base_url()."users/message/refresh_div/"; ?>" + session_to_user); }, 10000); }
Comments
Post a Comment