hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
 
counter
Select Country/Language FrancaisDeutschEspanolItalianoPortugeseJapaneseKoreanChineseArabicRussianEnglish
Current Projects
portland paranormal.com
xxk search
battlenow
bighawk casino
Hawk Enterprises News

PHP AJAX CHAT updates text run-off problem

Tags: , , by Hawk on 05.13.08 6:06 am

As one of my audience so nicely pointed out we have a text run-over problem.  These are generally easy to fix, I tend to use a three prong approach.  For me I felt 30 characters was a good length.

First run

ALTER TABLE `chatbox` CHANGE `message` `message` VARCHAR( 30 )

This will fix it at the database level, but we don’t want it to even get that far so next we change the maxlength of the input.

<input type=”text” name=”textbox” id=”textbox” style=”width:110px” maxlength=”30″ onkeypress=”formsubmit(event)”/>

Notice the “maxlength” attribute, it’s not always followed by browsers and thus we also do this here with the javascript

chatsend = document.getElementById(”textbox”).value;
if(chatsend.length < 30){
guyname = document.getElementById(”guyname”).value;
parameters = “nick=”+encodeURI(guyname)+”&textbox=”+encodeURI(chatsend);
httpr.onreadystatechange = handleResponse;
httpr.open(”POST”, “<?php echo $url;?>rpc.php”,true);
httpr.setRequestHeader(”Content-type”, “application/x-www-form-urlencoded”);
httpr.setRequestHeader(”Content-length”, parameters.length);
httpr.send(parameters);
document.getElementById(’textbox’).value = ”;
}else{
document.getElementById(’textbox’).value = ‘too large to send’;
}

The code above basically stops the user from entering too much text and will inform them if they do.  This will go into the javascript between the if(doit) block.   But once again javascript fixes can be avoided, that is why we did the database length as well.   We could also check it at the rpc level but we want to keep that as fast as possible and well I will modify it at that point if someone figures a way.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.