4 Replies - 7861 Views - Last Post: 12 December 2011 - 10:46 PM Rate Topic: -----

#1 shebby  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 29-June 11

When send message button is clicked the scroll cannot be bottom

Posted 12 December 2011 - 09:13 PM

Screenshots

Posted Image


Im has two iframe that are chatlog.php and form2.php

Chatlog.php

<html>
<head>
<script type="text/javascript">

var refreshPeriod = 120; // 120 Seconds

            function refresh()
            {
                document.cookie = 'scrollTop=' + filterScrollTop();
                document.cookie = 'scrollLeft=' + filterScrollLeft();
                document.location.reload(true);
            }

            function getCookie(name)
            {
                var start = document.cookie.indexOf(name + "=");
                var len = start + name.length + 1;

                if(((!start) && (name != document.cookie.substring(0, name.length))) || start == -1)
                    return null;

                var end = document.cookie.indexOf(";", len);

                if(end == -1)
                    end = document.cookie.length;

                return unescape(document.cookie.substring(len, end));
            }

            function deleteCookie(name)
            {
                document.cookie = name + "=" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
            }

            function setupRefresh()
            {
                var scrollTop = getCookie("scrollTop");
                var scrollLeft = getCookie("scrollLeft");

                if (!isNaN(scrollTop))
                {
                    document.body.scrollTop = scrollTop;
                    document.documentElement.scrollTop = scrollTop;
                }

                if (!isNaN(scrollLeft))
                {
                    document.body.scrollLeft = scrollLeft;
                    document.documentElement.scrollLeft = scrollLeft;
                }

                deleteCookie("scrollTop");
                deleteCookie("scrollLeft");

                setTimeout("refresh()", 2000);
            }

            function filterResults(win, docEl, body)
            {
                var result = win ? win : 0;

                if (docEl && (!result || (result > docEl)))
                    result = docEl;

                return body && (!result || (result > body)) ? body : result;
            }

            // Setting the cookie for vertical position
            function filterScrollTop()
            {
                var win = window.pageYOffset ? window.pageYOffset : 0;
                var docEl = document.documentElement ? document.documentElement.scrollTop : 0;
                var body = document.body ? document.body.scrollTop : 0;
                return filterResults(win, docEl, body);
            }

            // Setting the cookie for horizontal position
            function filterScrollLeft()
            {
                var win = window.pageXOffset ? window.pageXOffset : 0;
                var docEl = document.documentElement ? document.documentElement.scrollLeft : 0;
                var body = document.body ? document.body.scrollLeft : 0;
                return filterResults(win, docEl, body);
            }


</script>
</head>
<body onload="setupRefresh()">
<?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password
mysql_select_db("cute") or die(mysql_error());

$getnummessages="SELECT COUNT(*) as messagecount from chatmessages";

$getnummessages2=mysql_query($getnummessages) or die("blah");

$getnummessages3= mysql_result($getnummessages2, 0);

if($getnummessages3>40)

{

   $startrow=$getnummessages3-20;

}

else

{

  $startrow=0;

}

$getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3";

$getmsg2=mysql_query($getmsg) or die(mysql_error());

function replacesmiley($msg)
{
         $msg = str_replace(':)/>', '<img src="smile.gif" alt=":)/>" />', $msg);
         $msg = str_replace(':(/>', '<img src="sad.gif" alt=":(/>" />', $msg);
         $msg = str_replace(':P/>', '<img src="tongue.gif" alt=":P/>" />', $msg);
         return $msg;
}

echo replacesmiley($text);

 function filterBadWords($str)
 {
    $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); 
    $replacements = "*";
    
    while($row = mysql_fetch_assoc($result))
    {
          $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str);
    }  
    
    return $str;
}



while($getmsg3=mysql_fetch_array($getmsg2))

{

  $getmsg3['message'] = replacesmiley($getmsg3['message']);
  $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces
  print "<hr><font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>";



}






?>

</body>
</html>




Form2.php

<?php
session_start();
if (empty($_SESSION['is_logged_in']))
{
 header("Location:chatframe.php");
 die();     // just to make sure no scripts execute
} 
?>
<?php
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("cute") or die(mysql_error());
$message=$_POST['message'];
$a=$_SESSION['username'];



if(isset($_POST['submit'])) //if submit button push has been detected

{


   if(strlen($message)>1)
   {
      $message=strip_tags($message);
      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP
      $checkforbanned="SELECT IP from ipbans where IP='$IP'";
      $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");

    if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list
    {
     print "You IP is banned from posting.";
    }

    else
    {
     $thedate = date("U"); //grab date and time of the post
     $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$a','$IP','$thedate','$message')";
     mysql_query($insertmessage) or die("Could not insert message");
     $a="chatlog2.php";
      echo "<script>setTimeout('window.location.replace($a)',2000)
     var objDiv = document.body
     objDiv.scrollTop = objDiv.scrollHeight
   </script> ";
    }
  }

}

 ?>

<html>
<head>
<script type="text/javascript">
function addsmiley(code)
{
var pretext = document.smile.message.value;
              this.code = code;
              document.smile.message.value = pretext + code;
}

function a()
{
 var x = document.smile.message.value;
 if(x=="")
 {
  alert("Please insert an message!");
  return false;
 }

}

</script>
<style type="text/css">
body{ background-color: #d8da3d }
</style>
</head>
<body>
<center>
  <form name="smile" method="post" action="form2.php" onsubmit="return a()" >
   Your message:&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <a style="text-decoration:none" <a href="javascript: void(0)"
   onclick="window.open('banip.php',
  'windowname2',
  'width=400, \
   height=150, \
   directories=no, \
   location=no, \
   menubar=no, \
   resizable=no, \
   scrollbars=1, \
   status=no, \
   toolbar=no');
  return false;">Action</a>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
   <a style="text-decoration:none" href="logout.php">Sign Out</a><br><textarea name='message' cols='40' rows='2'></textarea><br>
   <img src="smile.gif" alt=":)/>" onclick="addsmiley(':)/>')" style="cursor:pointer;border:0" />
   <img src="blush.gif" alt=":)/>" onclick="addsmiley('*blush*')" style="cursor:pointer;border:0" />
    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
   <input type='submit' name='submit' value='Send' class='biasa'  ></form>

   
 
  <br> <br>
  </center>
  </body>
</html>


My problem is as you saw the screenshot, iam want when the send message button is clicked,the scroll will be bottom on the chatlog and im had done the script but still nothing happen iam wonder why?

Is This A Good Question/Topic? 0
  • +

Replies To: When send message button is clicked the scroll cannot be bottom

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: When send message button is clicked the scroll cannot be bottom

Posted 12 December 2011 - 10:31 PM

Why did you use iframes here? Javascript is capable of handling this. Ajax would have worked a lot cleaner and faster in pertaining to updating the database instead of iframes.
Was This Post Helpful? 0
  • +
  • -

#3 shebby  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 29-June 11

Re: When send message button is clicked the scroll cannot be bottom

Posted 12 December 2011 - 10:34 PM

View Postcodeprada, on 12 December 2011 - 10:31 PM, said:

Why did you use iframes here? Javascript is capable of handling this. Ajax would have worked a lot cleaner and faster in pertaining to updating the database instead of iframes.



sorry Sir, I am don has basic ajax :( so that why I am using iframes but my main point is
why when I am put the form2.php that reload script it does not work?

 else
035
    {
036
     $thedate = date("U"); //grab date and time of the post
037
     $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$a','$IP','$thedate','$message')";
038
     mysql_query($insertmessage) or die("Could not insert message");
039
     $a="chatlog2.php";
040
      echo "<script>setTimeout('window.location.replace($a)',2000)
041
     var objDiv = document.body
042
     objDiv.scrollTop = objDiv.scrollHeight
043
   </script> ";
044
    }


This post has been edited by shebby: 12 December 2011 - 10:35 PM

Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: When send message button is clicked the scroll cannot be bottom

Posted 12 December 2011 - 10:43 PM

You're suppose to tell me if it's working or not. You need to check if
  • The database is being updated
  • The iframe is being reloaded
  • Javascript isn't crashing due to errors

Was This Post Helpful? 0
  • +
  • -

#5 shebby  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 29-June 11

Re: When send message button is clicked the scroll cannot be bottom

Posted 12 December 2011 - 10:46 PM

View Postcodeprada, on 12 December 2011 - 10:43 PM, said:

You're suppose to tell me if it's working or not. You need to check if
  • The database is being updated
  • The iframe is being reloaded
  • Javascript isn't crashing due to errors



actually sir
setTimeout("window.location.replace('chatlog.php')",2000);
 var objDiv = document.body;
 objDiv.scrollTop = objDiv.scrollHeight;
this part in my form2.php that is not loading im don know where the problem is because it does not deal with database only need to refresh the iframe
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1