Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2013, 08:38 AM   PM User | #1
J04h
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
J04h is an unknown quantity at this point
Why isn't this working? Help appreciated :D

Thanks in advance for taking a look at this, I'm a beginner at this. If I were to replace function(){ document.getElementById("stsbutton").innerHTML="<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit"/>";} with something else like an alert() it works 3 seconds after loading the page, otherwise nothing happens.

What I currently have (red&bold code does not work):

Code:
<script type="text/javascript">
var myCounter = new Countdown({  
    seconds:3,  // number of seconds to count down
    onUpdateStatus: function(sec){console.log(sec);}, // callback for each second
    onCounterEnd: function(){ document.getElementById("stsbutton").innerHTML="<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit"/>";}
});

myCounter.start();

function Countdown(options) {
  var timer,
  instance = this,
  seconds = options.seconds || 10,
  updateStatus = options.onUpdateStatus || function () {},
  counterEnd = options.onCounterEnd || function () {};

  function decrementCounter() {
    updateStatus(seconds);
    if (seconds === 0) {
      counterEnd();
      instance.stop();
    }
    seconds--;
  }

  this.start = function () {
    clearInterval(timer);
    timer = 0;
    seconds = options.seconds;
    timer = setInterval(decrementCounter, 1000);
  };

  this.stop = function () {
    clearInterval(timer);
  };
}

function SetButtonStatus(sender, target)
{

if ( sender.value.length >= 12 )
document.getElementById(target).disabled = false;

else

document.getElementById(target).disabled = true;
}

</script>

<script type="text/javascript">
var myCounter = new Countdown({  
    seconds:2,  // number of seconds to count down
    onUpdateStatus: function(sec){console.log(sec);}, // callback for each second
    onCounterEnd: function(){ document.getElementById("stsbutton").innerHTML="<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit"/>";}
});

myCounter.start();

function Countdown(options) {
  var timer,
  instance = this,
  seconds = options.seconds || 10,
  updateStatus = options.onUpdateStatus || function () {},
  counterEnd = options.onCounterEnd || function () {};

  function decrementCounter() {
    updateStatus(seconds);
    if (seconds === 0) {
      counterEnd();
      instance.stop();
    }
    seconds--;
  }

  this.start = function () {
    clearInterval(timer);
    timer = 0;
    seconds = options.seconds;
    timer = setInterval(decrementCounter, 1000);
  };

  this.stop = function () {
    clearInterval(timer);
  };
}

function SetButtonStatus(sender, target)
{

if ( sender.value.length >= 12 )
document.getElementById(target).disabled = false;

else

document.getElementById(target).disabled = true;
}

</script>

<div id="stsbutton"><b>Submit</b> button will be available in <b>3</b> seconds...</div>
J04h is offline   Reply With Quote
Old 01-09-2013, 09:45 AM   PM User | #2
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 143
Thanks: 3
Thanked 38 Times in 38 Posts
niralsoni is an unknown quantity at this point
Are you sure the syntax is correct ? From the code you have given here -
Code:
onCounterEnd: function(){ document.getElementById("stsbutton").innerHTML="<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit"/>";}
it seems that there is error in the usage of quotes. The correction will be as given below -
Code:
onCounterEnd: function(){ document.getElementById("stsbutton").innerHTML='<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit"/>';}
niralsoni is offline   Reply With Quote
Old 01-09-2013, 11:36 AM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Also, from the code you have shown then (apart from the duplication) your code runs before "stsbutton" exists on the page. Put your scripts at the end of the page (before the closing body-tag) or wait until the page has finished loading:

Code:
window.onload = some_function;
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:12 AM.


Advertisement
Log in to turn off these ads.