How do I make it autoscroll to bottom of chat again?

[php]<?php
session_start();

function loginForm(){
echo’



Please enter your name to continue:


Name:




';
}

if(isset($_POST[‘enter’])){
if($_POST[‘name’] != “”){
$_SESSION[‘name’] = stripslashes(htmlspecialchars($_POST[‘name’]));

	//Clear file
	$fp = fopen("log.html", 'w');
	fclose($fp);
	
	$fp = fopen("log.html", 'a');
	$fp2 = fopen("longlog.html", 'a+');
	fwrite($fp, "<div class='msgln' id=" . time() ."><i>User ". $_SESSION['name'] ." has entered the chat session.</i><br></div>");
	fwrite($fp2, "<div class='msgln' id=" . time() ."><i>User ". $_SESSION['name'] ." has entered the chat session.</i><br></div>");
	fclose($fp);
	fclose($fp2);
}
else{
	echo '<span class="error">Please type in a name</span>';
}

}
?>

KappaChat <?php if(!isset($_SESSION['name'])){ loginForm(); } else{ if(isset($_GET['logout'])){ //Clear file $fp = fopen("log.html", 'w'); fclose($fp); //Simple exit message $fp = fopen("log.html", 'a'); $fp2 = fopen ("longlog.html", 'a+'); fwrite($fp, "
User ". $_SESSION['name'] ." has left the chat session.
"); fwrite($fp2, "
User ". $_SESSION['name'] ." has left the chat session.
"); fclose($fp); fclose($fp2); session_destroy(); echo ''; //Show login form again } ?>

Have a cucumber, <?php echo $_SESSION['name']; ?>

Exit Chat

<?php if(file_exists("log.html") && filesize("log.html") > 0){ $handle = fopen("log.html", "r"); $contents = fread($handle, filesize("log.html")); fclose($handle);
	echo $contents;
}
?></div>

<form name="message" method="post">
	<input name="usermsg" type="text" id="usermsg" size="63" />
	<input name="submitmsg" type="submit"  id="submitmsg" value="Send" />
</form>
<?php } ?> [/php]

[php]<?php
session_start();
if(isset($_SESSION[‘name’])){
$text = $_POST[‘text’];

//Clear file
$fp = fopen("log.html", 'w');
fclose($fp);

$fp = fopen("log.html", 'a');
$fp2 = fopen("longlog.html", 'a+'); 
fwrite($fp, "<div class='msgln' id=" . time() .">(".date("g:i A").") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
fwrite($fp2, "<div class='msgln' id=" . time() .">(".date("g:i A").") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
fclose($fp);
fclose($fp2);

}
?>[/php]

It worked before, just fine. Sadly, I forgot to save a copy of it when it worked. I did not altar the scroll area of the index at all since it worked. Just other areas. Here’s the two big files… index and post…respectively.

It looks like you modified this section last time…

[php] //Autoscroll to new bottom of #chatbox if previously at bottom of #chatbox
var newscrollHeight = $("#chatbox").prop(“scrollHeight”) - 20;
if(scrolltop == (oldscrollHeight-270) && newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, ‘normal’);
}[/php]

Maybe just replace it with

[php] //Autoscroll to new bottom of #chatbox if previously at bottom of #chatbox
var newscrollHeight = $("#chatbox").prop(“scrollHeight”) ;
$("#chatbox").animate({ scrollTop: newscrollHeight }, ‘normal’);
[/php]

which will always put it at the bottom.

Sponsor our Newsletter | Privacy Policy | Terms of Service