So I am trying to allow the user to enter an "access code" which is simply a timestamp, and then start a countdown timer based on that. I can set the var manually and it works, but I cannot get it from the form. What am I missing?
HTML
<form>
<input type="text" name="access" onkeyup="formChanged()" onchange="formChanged()" />
<button type="submit" class="btn btn-default">Submit</button>
</form>
JQUERY
$(function() {
function formChanged() {
var access = document.getElementsByName("access")[0].value;
}
//var access = 1443564011;
var note = $('#note'),
// Notice the *1000 at the end - time must be in milliseconds
ts = (new Date(access * 1000)).getTime() + 1 * 24 * 60 * 60 * 1000;
$('#countdown').countdown({
timestamp: ts,
callback: function(days, hours, minutes, seconds) {
var message = "";
message += days + "<small class='white'>D</small>, " + access;
message += hours + "<small class='white'>H</small>, ";
message += minutes + "<small class='white'>M</small>, ";
message += seconds + "<small class='white'>S</small>";
note.html(message);
}
});
});
tsis set only once and it is set before the user gets s chance to enter any input. Perhaps you should move the countdown () call to insideformChanged2. You're already using jQuery. Go ahead and make it easy on you self to bindformChanged.$('form input[name=access]').on ('keypress change',formChanged);