function setIcon(iconName, iconText) { document.getElementById('iconValue').value = iconName; document.getElementById('selected-icon').innerHTML = ' ' + iconText; } $( document ).ready( function () { function autosave() { var title = $( "#title" ).val(); var color = $( "#color" ).val(); var notebookID = $( "#notebookID" ).val(); var noteID = $( "#noteID" ).val(); var note = $( "#note" ).val(); $.post( "/notes/autoUpdate/" + noteID, { title: title, color: color, notebookID: notebookID, note: note, }); console.log( 'note saved' ); } var lastSegment = window.location.pathname.split('/').pop(); if (!isNaN(lastSegment)) { if (window.location.pathname.endsWith('/notes/byNote/'+lastSegment)) { console.log( 'autosave enabled' ); setInterval(autosave, 60 * 1000); } } });