Skip to main content

OTP verification 2 minutes count down timer

Java Script

 let timerOn = true;

function timer(remaining) {

  var m = Math.floor(remaining / 60);

  var s = remaining % 60;

  m = m < 10 ? '0' + m : m;

  s = s < 10 ? '0' + s : s;

  document.getElementById('timer').innerHTML = m + ':' + s;

  remaining -= 1;

  if(remaining >= 0 && timerOn) {

    setTimeout(function() {

        timer(remaining);

    }, 1000);

    return;

  }

  if(!timerOn) {

    // Do validate stuff here

    return;

  }

  // Do timeout stuff here

  alert('Timeout for otp');

}

// Then Call the function of Timer //

timer(120);


HTML

<input type="text" name="otp" placeholer="Enter your otp"/>

<div>Time left = <span id="timer"></span></div>

Comments

Popular posts from this blog

Error: [Reanimated] valueUnpacker is not a worklet, js engine: hermes Fixed it with a version downgrade: npm install react-native-reanimated@3.4.2 And editing the babel.config.js file: module.exports = {   presets: ['module:metro-react-native-babel-preset'],   plugins: ['react-native-reanimated/plugin'], }; 
 jQuery select change show/hide div event <script>   $(document).ready(function(){     $('#selectID').on('change', function() {       if ( this.value == 'red')       {         $("#divid").show();       }       else       {         $("#divid").hide();       }     }); }); </script>
Fetch not working in release APK - React Native Make sure your config.urlServer is not an HTTP endpoint but should be HTTPS. Latest RN versions target recent Android SDK that blocks insecure HTTP connections automatically. Quick Fix: Adding android:usesCleartextTraffic="true" in <application> tag in android\app\src\main\AndroidManifest.xml will work.