View Full Version : onsubmit - refresh div?
I was woundering how you refresh a div (Like on Habbo homes when you submit a comment) when you submit a form?
Moved by Agesilaus (Forum Moderator) from Designing and Development: Please post in the correct forum next time. :)
Using ajax, I didn't write this my friend Nick did but here's what I use for my shoutbox..
<script type="text/javascript" language="javascript">
var xmlHttp
function GetXmlHttpObject(){
var objXMLHttp = null;
if(window.XMLHttpRequest){
try{
objXMLHttp = new XMLHttpRequest();
}catch (e){
objXMLHttp = false;
}
}else if(window.createRequest){
try{
objXMLHttp = new window.createRequest();
}catch (e){
objXMLHttp = false;
}
}else if(window.ActiveXObject){
try{
objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
objXMLHttp = false;
}
}
}
return objXMLHttp;
}
function GetShouts()
{
xmlHttp = GetXmlHttpObject()
if (xmlHttp == null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="shoutbox.php"
//The file you're using to display the entries/shouts most likely the current file..
xmlHttp.open("GET", url, true)
xmlHttp.onreadystatechange = function ()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
document.getElementById("shoutarea").innerHTML = xmlHttp.responseText;
//Shoutarea is the id of my div the shouts appear in so change that accordingly.
}
}
};
xmlHttp.send(null);
}
GetShouts();
setInterval("GetShouts()", 1000);
function saveData()
{
xmlHttp = GetXmlHttpObject()
if (xmlHttp == null)
{
alert ("Browser does not support HTTP Request")
return
}
xmlHttp.open('POST', 'shouts.php');
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send('&name=' + document.shout.name.value + '&shout=' + document.shout.message.value);
//document.shout.name.value is the field the user would enter their name there's also one for the message field do this for every input you have.
document.shout.message.value = '';
document.shout.message.focus();
}
</script>
I'm absolute balls with javascript so i wont be able to help with problems but this works fine for me :P
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.