Jump to content


Javascript character limit in MKPortal Shoutbox


1 reply to this topic

#1 visiblesoul

  • Administrators
  • 551 posts
  • Location:Earth
  • Texas

Posted 09 June 2008 - 07:02 AM

Mod type: Hack
Current version: 1.0
Compatible with: M1.0 - C1.2 rc2
Author: visiblesoul
Download: N/A
Demo: N/A
Description:

How to limit characters and display an update of characters remaining in Shoutbox using javascript

Tested with FF2 and IE7.

FIND in mkportal/modules/urlobox/index.php:
<textarea cols="10" style="width:75%" rows="12" name="ta"></textarea>
REPLACE WITH:
	";	  
	  //Limit characters
	  $charlim = 50; //How many characters to allow
	
	$output .= "
		  <script language="javascript" type="text/javascript">
		  function limitText(limitField, limitCount, limitNum) {
			if (limitField.value.length > limitNum) {
				  limitField.value = limitField.value.substring(0, limitNum);
				} else {
				  limitCount.value = limitNum - limitField.value.length;
				}
		  }
		  </script>
		  
		  <textarea cols="10" style="width:75%" rows="12" name="ta" onkeydown="limitText(this.form.ta,this.form.countdown,$charlim);" onkeyup="limitText(this.form.ta,this.form.countdown,$charlim);"></textarea>

		  <div>(Maximum characters: $charlim) You have <input readonly="readonly" type="text" name="countdown" size="3" value="$charlim" /> characters left.</div>
Set your character limit by replacing "50" on this line with your desired limit...

$charlim = 50;
Keep in mind that the real limit is set in the database and not in the javascript. It is possible to bypass the javascript limit.


The default datatype for the mkp_urlobox "message" field is "TEXT.This allows very long messages. To impose a much lower limit in the database such as 50 characters run this query...


BACKUP YOUR DATABASE FIRST! No Warranty.

ALTER TABLE `mkp_urlobox` CHANGE `message` `message` VARCHAR( 50 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL

Quote

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

from: http://dev.mysql.com....0/en/char.html
You may need to know a little about MySQL data types and data type storage requirements. The MySQL reference pages are here...

http://dev.mysql.com...ring-types.html
http://dev.mysql.com/doc/refman/5.0/en/sto...quirements.html


Please note that I offer free support on this forum in my free time. Depending on how much work I have backlogged it may take me a week or more to answer questions. I am not ignoring you. I answer everyone but please be patient. Thanks.

Disclaimer: All forum posts, including code examples, on this forum are offered for free in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Use code examples at your own risk.

"If at first you don't succeed, keep on suckin' til you do succeed." -Curly Howard

#2 visiblesoul

  • Administrators
  • 551 posts
  • Location:Earth
  • Texas

Posted 09 June 2008 - 07:02 AM

Note that this can be adapted for use with any textarea.

Just be sure to change the "ta" in the javascript to the actual "name" of your textarea.

this.form.ta
this.form.yourtextareaname



Please note that I offer free support on this forum in my free time. Depending on how much work I have backlogged it may take me a week or more to answer questions. I am not ignoring you. I answer everyone but please be patient. Thanks.

Disclaimer: All forum posts, including code examples, on this forum are offered for free in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Use code examples at your own risk.

"If at first you don't succeed, keep on suckin' til you do succeed." -Curly Howard





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users