Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery set time out function

Tags:

jquery

What is wrong in this function?

function getTuittingCookie() {
var tuitting_cookie = $.cookie("tuittingID");
$("#tuittingID").val(tuitting_cookie);
//alert(tuitting_cookie);
setTimeout(getTuittingCookie, 2000);
}

It should write the value every 2 seconds on the field:

<input id="tuittingID" style="display:none" value=""/>

But instead it does not write anything at all!

Can you help me please?

like image 325
DiegoP. Avatar asked Jul 09 '26 20:07

DiegoP.


1 Answers

Are you calling function getTuittingCookie() in your code . this code works for me see example at http://jsfiddle.net/Z9dcb/2/

function getTuittingCookie() {
var tuitting_cookie= Math.floor(Math.random()*11)
$("#tuittingID").val(tuitting_cookie);
//alert(tuitting_cookie);
setTimeout(getTuittingCookie, 2000);
}
getTuittingCookie();

and in place of using code

you could use

<input id="tuittingID" type="hidden" value=""/>
like image 109
Vivek Goel Avatar answered Jul 16 '26 00:07

Vivek Goel