jquery - Get value from html form to Javascript variable -


i have been searching issues while can't find solution helps me, maybe i'm stupid @ javascript don't kow. problem title says.

i have countdown timer found here on stackoverflow, , written in javascript. not @ javascript (i'm totally newb in it). asking javascript pro me out.

i want make simple html form set "var target = 14;" value can be. have no idea pass through form in admin system.

the core code:

if (document.getelementbyid('countdowntimer')) { pad = function(n, len) { // leading 0's var s = n.tostring(); return (new array( (len - s.length + 1) ).join('0')) + s;};var timerrunning = setinterval( function countdown() {     var = new date();     var target = 14; // 15:00hrs cut-off point     if (now.getday() == 0) { // sunday - use tomorrow's cutoff         target += 24;     } else if (now.getday() == 6) { // saturday - use cutoff 2 days         target += 48;     } else if (now.gethours() < target) { // missed cutoff point. use tomorrow instead         target += 24;         if (now.getday() == 5) { // friday - use monday cutoff             target += 48;         }      }     var hrs = (target - 1) - now.gethours();     if (hrs < 0)         hrs = 0;     var mins = 59 - now.getminutes();     if (mins < 0)         mins = 0;     var secs = 59 - now.getseconds();     if (secs < 0)         secs = 0;     var str = pad(hrs, 2) + ':' + pad(mins, 2) + '.<small>' + pad(secs, 2) + '</small>';     document.getelementbyid('countdowntimer').innerhtml = str; }, 1000);} 

the html call id:

<div id="countdowntimer">0</div> 

i didn't down vote question, though justified. question vague , sample code horribly ugly. yet, appears op wants "simple form" set expire time. that's easy, i'm not sure "how pass form through admin" ... address , stamps maybe?

simple form: - et phone home

<!doctype html>  <html>  <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8">  <title>simple form</title>  </head>  <body>    <fieldset style="padding: 10px;">  	<legend>et phone home</legend>  	enter hour: <input type="text" value="14" id="target" style="border: 1px red solid;"/>  </fieldset>    <div id="countdowntimer"></div>    <script type="text/javascript">      setinterval( countdown, 1000);    function pad(n) {   	return ((n < 10 ? '0' : '') + n);  };  		  function countdown() {      var = new date();      var target = parseint( document.getelementbyid('target').value );      if (now.getday() == 0) {      	target += 24;       }      else if (now.getday() == 6) {           target += 48;      }       else if (now.gethours() < target) {  		target += 24;  		if (now.getday() == 5) target += 48;      }      var hrs = (target - 1) - now.gethours();      if (hrs < 0) hrs = 0;      var mins = 59 - now.getminutes();      if (mins < 0) mins = 0;      var secs = 59 - now.getseconds();      if (secs < 0) secs = 0;      var str = pad(hrs) + ':' + pad(mins) + '.<small>' + pad(secs) + '</small>';            now.sethours( now.gethours() + target );            document.getelementbyid('countdowntimer').innerhtml = str;  }  </script>  </body>  </html>


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -