window.onload = function() { // some code here dbg("Window loaded..."); document.getElementById('send').onclick = sendForm; document.getElementById('show').onclick= setRefresher; //document.getElementById("jsonp").onload = showData; document.getElementById("delete").onclick = function() { var father = document.getElementById('text'); if ( father.children ) { killKid(father); } }; }; // Debugger function ///////////////////////////////////////////////////////////////////////////////////////////////////////// function dbg(text) { console.log(text[0].name); } // make children and append them to father function makeKid(type, data, father) { var kido = document.createElement(type); kido.innerHTML = data; father.appendChild(kido); } //flush all childrem function killKid(father) { //father.removeChild(father.children[0]); for ( var i=father.children.length-1; i >= 0; i-- ) { father.removeChild(father.children[i]); } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* var showData = function (data) { console.log("showData() called"); var div = document.getElementById('text'); if ( ! div.children[0] ) { for ( var i=0; i < data.length; i++ ) { console.log(i); makeKid("p", data[i].name, div); makeKid("p", data[i].id, div); makeKid("p", data[i].age, div); } } } */ /*000000000000000000000000000000000000000000000000000000000000000000*/ function setRefresher() { dbg("setRefresher called"); var rnd = "&rnd="+Math.floor(Math.random() * 12345); var dat = "&time="+new Date().getTime(); var url = "http://localhost/dat.json?callback=dbg"; var newScript = document.createElement('script'); newScript.setAttribute('src', url); newScript.setAttribute('id', 'jsonp'); var head = document.getElementsByTagName('head')[0]; if ( !document.getElementById('jsonp') ) { head.appendChild(newScript); dbg("setRefresher 1st option"); } else { var oldOne = document.getElementById('jsonp'); head.replaceChild(newScript, oldOne); dbg("setRefresher 2nd option"); } } /***************************************************************************************************************/ function sendForm() { var name = document.getElementById('name').value; var mail = document.getElementById('mail').value; var pass = document.getElementById('pass').value; if ( name && mail && pass ) { var url = "http://localhost/serv.pl?name="+name+"&mail="+mail+"&pass="+pass+"&rnd="+Math.floor(Math.random()*12345)+"&dat="+new Date().getTime(); var form = document.getElementById('form'); form.method = "get"; form.action = url; form.submit(); //window.location.replace(url); } else { // none } }