lundi 6 avril 2015

Javascript date dissapears when I change rails partial

html / haml :



- elsif statement.featured && statement.unanswered(current_user)
= javascript_include_tag "date"
%h4#dateDisplay
%h4.text-left#join_the_conversation_heading WHAT DO YOU THINK?
.statement_text= statement.text
= render "responses/response", :statement => statement
= render "statements/conversation_links", :statement => statement
.clear


js:



$(document).on("ready page:load", function() {
// this will return the current date in specified format.
function thisDate() {
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var today = new Date(),
dd = today.getDate(),
mm = month[today.getMonth()],
yyyy = today.getFullYear();
today = mm + ' ' + dd + ' , ' + yyyy;
dateDisplay = document.getElementById('dateDisplay');
dateDisplay.innerHTML = today;
}

thisDate();
//
});


whenever I click the next link to the next partial / statement, the date dissapears. It only shows on the first statement / partial when I initially load the page.


I'm not sure why this will show in the initial load an in the main page, but will not consistently display within the partial..


Aucun commentaire:

Enregistrer un commentaire