samedi 17 avril 2021

Check Box is Not Working As I Want It To Work

When I check the checkbox there is a timer in the text field that runs for 5 seconds, after the 5 seconds text field gets enabled for typing. Everything is fine at this moment but when I uncheck the checkbox within 5 seconds, it still gets enabled. I want that when I uncheck the check box, it should not enable.

Below is the code:

<html class='v2' dir='ltr' lang='en-us'>
<head lang="en">
<meta content='en_US' property='og:locale'/>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport'/>
</head>
<body>

<input type="text" id="custom" name="custom" class="input_custom" placeholder="Enable Text" disabled 
style="height: 50px;width: 400px;">

<input type="checkbox" name="onoffswitch" id="myonoffswitch" onclick="toggless()" 
style="height: 20px;width: 20px;">

<script>
function toggless() {
        if (document.getElementById('myonoffswitch').checked) {
            Timess();
}
else {
    document.getElementById('custom').value = ''
    document.getElementById('custom').placeholder = 'Enable Text'
    document.getElementById('custom').disabled = true
    }}
    
function Timess(){
  var timeleft = 5;
  var downloadTimer = setInterval(function function1(){
  document.getElementById("custom").placeholder = timeleft + 
  " "+"Seconds Remaining Enable Text";
  timeleft -= 1;
  if(timeleft <= 0){
      clearInterval(downloadTimer);
      document.getElementById('myonoffswitch').checked
      document.getElementById('custom').placeholder = 'Enter Your Text'
      document.getElementById('custom').disabled = false
      }}, 1000);
};
</script>
</body>
</html>



Aucun commentaire:

Enregistrer un commentaire