Results 1 to 2 of 2
  1. #1
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default 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.
    Last edited by Agesilaus; 04-01-2008 at 01:52 PM.

  2. #2

    Default

    Using ajax, I didn't write this my friend Nick did but here's what I use for my shoutbox..
    HTML Code:
    <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
    Last edited by Jme; 04-01-2008 at 11:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •