how should i call a javascript function into a kohana view? -


i having simple kohana view, , javascript makes countdown of 30 minutes. hava put javascript file directory /media m , name countdown.js . problem is: how can call javascript? form view? or controller displayed in view? , how may address in controller or view js function or functions?

thank you

the countdown js:

var javascript_countdown = function () { var time_left = 10; //number of seconds countdown var output_element_id = 'javascript_countdown_time'; var keep_counting = 1; var no_time_left_message = 'no time left javascript countdown!';

function countdown() {     if(time_left < 2) {         keep_counting = 0;     }      time_left = time_left - 1; }  function add_leading_zero(n) {     if(n.tostring().length < 2) {         return '0' + n;     } else {         return n;     } }  function format_output() {     var hours, minutes, seconds;     seconds = time_left % 60;     minutes = math.floor(time_left / 60) % 60;     hours = math.floor(time_left / 3600);      seconds = add_leading_zero( seconds );     minutes = add_leading_zero( minutes );     hours = add_leading_zero( hours );      return hours + ':' + minutes + ':' + seconds; }  function show_time_left() {     document.getelementbyid(output_element_id).innerhtml = format_output();//time_left; }  function no_time_left() {     document.getelementbyid(output_element_id).innerhtml = no_time_left_message; }  return {     count: function () {         countdown();         show_time_left();     },     timer: function () {         javascript_countdown.count();          if(keep_counting) {             settimeout("javascript_countdown.timer();", 1000);         } else {             no_time_left();         }     },     init: function (t, element_id) {         time_left = t;         output_element_id = element_id;         javascript_countdown.timer();     } }; 

}();

//time countdown in seconds, , element id javascript_countdown.init(3673, 'javascript_countdown_time');

you can use kohana html helpers. in controller function or view file, can have :

echo html::script('media/countdown.js'); 

place echo statement after html element id "javascript_countdown_time". before closing </body> if possible.

... <div id="javascript_countdown_time"></div> ... <script src="/media/countdown.js"></script> </body> 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -