//variables var dt; var hh; var el; var co; var type; var data; var summary; summary="NULL"; // default options function function getopt(){ select = document.getElementById('hh'); for (var i = 0; i<=24; i++){ var opt = document.createElement('option'); opt.value = i; opt.innerHTML = i; select.appendChild(opt); } document.getElementById("hh").value=0; select = document.getElementById('el'); for (var i = 0; i<=90; i++){ var opt = document.createElement('option'); opt.value = i; opt.innerHTML = i; select.appendChild(opt); } document.getElementById("el").value=17; } // date input function $(function init() { $('#dtpicker').datetimepicker({ dayOfWeekStart : 1, format:'dMY H:00', lang:'en', startDate:currentDate }); var currentDate = new Date(); $('#dtpicker').datetimepicker({value:currentDate,step:60}); }); //read form function read(form){ dt=form.dt.value; hh=form.hh.value; el=form.el.value; co=form.coord.value; co=co.trim(co); co=co.replace(/["]+/g, ' '); co=co.replace(/[\n]+/g, 'newline'); co=encodeURIComponent(co); } // calculate and save function cal(type) { // generate summary if(type == 1) { document.getElementById("table").innerHTML="Please wait...Generating summary(table)..."; $.get("./star_diff.php?dt="+ dt + "&hh=" + hh + "&el=" + el + "&co=" + co, function(data,status) {document.getElementById("table").innerHTML=data;summary=data;}); } if(type == 2) { //download summary if(summary == "NULL") { alert("please calculate before save");exit;} download("summary.txt",summary); } } function download(filename, summary) { var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(summary)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); }