I am using the countTimer plugin for a little online exam app. The idea is when the timer reaches zero, I want to redirect the user to a given url (to an action called time_expired in the questions controller). So the url is in the form: /questions/:id/time_expired.
In the show.html.erb of questions controller, I have the following div element:
<div id="count-down" data-url=<%= time_expired_path %> ></div>
Its in this div that I display the timer.
Now in my application.js file I want to grap the value of the data-url attribute of my div and use expiryUrl to direct to that url.
$(document).ready(function(){
myUrl = $("div").attr("data-url");
alert(myUrl); // Prints undefine
$('#count-down').countdown({expiryUrl: myUrl, format: 'MS', until: +10)
});
Why is the varibale “myUrl” undefined? I can check the value with firebug and there is indeed a url in my div.
Here is the firebug output:
<div id="count-down" data-url="/questions/2/time_expired"></div>
rails version: 3.2.8
Ruby Version : 1.9.3
Jquery: Jquery rails that comes shipped with rails
Any help and suggestion appreciated.
Try this instead: