function clear_text_name() { if (document.form.nick.value == "Name") { document.form.nick.value = ""; } } function clear_text_message() { if (document.form.message.value == "Enter Message") { document.form.message.value = ""; } } function show_text_name() { if (document.form.nick.value == "") { document.form.nick.value = "Name"; } } function show_text_message() { if (document.form.message.value == "") { document.form.message.value = "Enter Message"; } } /***************************/ //@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro //@website: www.yensdesign.com //@email: yensamg@gmail.com //@license: Feel free to use it, but keep this credits please! /***************************/ $(document).ready(function(){ //global vars var inputUser = $("#nick"); var inputMessage = $("#message"); var messageList = $(".content"); //functions function updateShoutbox(){ //just for the fade effect //send the post to shoutbox.php $.ajax({ type: "POST", url: "/shoutbox.php", data: "action=update&owner=fshs24p10784", complete: function(data){ messageList.html(data.responseText); messageList.fadeIn(2000); $("#container").animate({ scrollTop: $("#container")[0].scrollHeight}, 1000); } }); } //check if all fields are filled function checkForm(){ if(inputUser.attr("value") && inputMessage.attr("value")) if((inputUser.attr("value")=="Name") || (inputMessage.attr("value") == "Message")) return false; else return true; else return false; } //Load for the first time the shoutbox data updateShoutbox(); setInterval(updateShoutbox, 10000); //on submit event $("#form").submit(function(){ if(checkForm()){ var nick = inputUser.attr("value"); var message = inputMessage.attr("value"); //we deactivate submit button while sending //$("#send").attr({ disabled:true, value:"Sending..." }); //$("#send").blur(); //send the post to shoutbox.php $.ajax({ type: "POST", url: "/shoutbox.php", data: "action=insert&owner=fshs24p10784&nick=" + nick + "&message=" + message, complete: function(data){ //messageList.html(data.responseText); updateShoutbox(); //reactivate the send button $("#send").attr({ disabled:false, value:"Send" }); $("#message").attr({ disabled:false, value:"" }); $("#message").focus(); $('#nick').parent().addClass('d-none'); $('#container').css('bottom','58px'); //$('#nick').removeClass('form-control'); } }); } else alert("Please fill all fields!"); //we prevent the refresh of the page after submitting the form return false; }); });