-1

This is my jquery code:

 $('#txndatetime_reload_uk').val(values[2]);
 $('#customerid_reload_uk').val(sanderEmail);
  setTimeout(6000); 
   // alert('ok');
 $( '#activate_form_uk').submit();

I want to wait before submit the form for 6 seconds.

But setTimeout(6000); is not working.

What am I doing wrong in it?

unknownbits
  • 2,855
  • 10
  • 41
  • 81

4 Answers4

5

Try

setTimeout(function () {
    $('#activate_form_uk').submit()
}, 6000)

setTimeout() takes two arguments:

  1. function to execute
  2. amount of millisecond to wait before calling that function.
Josh Harrison
  • 5,927
  • 1
  • 30
  • 44
Vlas Bashynskyi
  • 1,886
  • 2
  • 16
  • 25
1

setTimeout runs asynchronously. So directly after it is called $('#activate_form_uk').submit(); gets executed. You need to pass a callback to setTimeout which gets executed after the 6 seconds:

setTimeout(function() { $( '#activate_form_uk').submit(); }, 6000);

Florian Gl
  • 5,984
  • 2
  • 17
  • 30
0

Use like below,

 setTimeout(function(){$( '#activate_form_uk').submit()}, 6000);
Anto king
  • 1,222
  • 1
  • 13
  • 26
0

Use .delay()

$('#activate_form_uk').delay(6000).submit()
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49