Advertise Here

Author Topic: [Code] Check Post Length Box  (Read 2895 times)

0 Members and 1 Guest are viewing this topic.

Offline webworldx

  • Code Master's
  • *
  • Posts: 31
    • View Profile
    • InvisionFusion

  • Total Badges: 15
    Badges: (View All)
    Windows User Topic Starter Combination Level 3 Level 2
[Code] Check Post Length Box
« on: June 26, 2006, 10:23:59 am »
Code: [Select]
<script type='text/javascript'>
/*
[SMF] Check Post Length
Created by iFusion
*/
var max_post_length = 255;
function checkPostLength(event){
  if(event && event.keyCode && event.keyCode == 17) return false;
  document.getElementById('my_post_error').innerHTML = "";
  var chars_left = Math.floor(max_post_length) - Math.floor(document.postmodify.message.value.length);
  if(chars_left < 0){
   document.postmodify.message.value = document.postmodify.message.value.substring(0, max_post_length);
    chars_left=0;
    document.getElementById('my_post_error').innerHTML = "<br />Your post exceeded the maximum length and may have been trimmed";
  }
  document.getElementById('my_post_length').value = chars_left;
}

if(location.href.match(/action=post/i) != null && document.postmodify){
  var my_node = document.postmodify.message.parentNode;
  var e = document.postmodify.message;

  if(e.addEventListener) {
    e.addEventListener ("keydown",checkPostLength,false);
  } else if (e.attachEvent) {
    e.attachEvent ("onkeydown",checkPostLength);
  } else {
    e.onkeydown = checkPostLength;
  }

  var my_box = document.createElement('SPAN');
  my_box.innerHTML = 'Chars Left: <input id="my_post_length" size="8" value="' + max_post_length + '" /> <span id="my_post_error" style="color: #FF0000; font-weight: bold;"></span>';
  my_node.appendChild(my_box);
}
</script>

Footer.

It's a bit longer than it could be, but i've added a few extra features like telling you if you've pasted something that's going to be trimmed, and stopping a user entering more characters than allowed (so they don't type it all then get an error and lose it).

Again, let me know if you have any problems, as I can't test it on all skins! :)
« Last Edit: August 27, 2007, 08:54:21 pm by simply sibyl »

Offline zammymage

  • SMF For Free Full Member
  • *
  • Posts: 108
    • View Profile

  • Total Badges: 14
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: [Code] Check Post Length Box
« Reply #1 on: December 26, 2008, 12:30:29 pm »
kool ill use this

Offline heinandar

  • SMF For Free Newbie
  • *
  • Posts: 1
    • View Profile

  • Total Badges: 8
    Badges: (View All)
    Topic Starter Combination Level 2 Level 1 First Post
Re: [Code] Check Post Length Box
« Reply #2 on: April 30, 2009, 05:55:45 pm »
it did'n work for me
I use dilbermc themes and smf 1.1.8

Offline simply sibyl

  • Helpers
  • *
  • Posts: 14347
  • On hiatus
    • View Profile
    • The Tent Dwellers

  • Total Badges: 31
    Badges: (View All)
    Level 6 Poll Voter Webmaster Arcade Highscore Windows User
Re: [Code] Check Post Length Box
« Reply #3 on: April 30, 2009, 06:27:56 pm »
it did'n work for me
I use dilbermc themes and smf 1.1.8

Hi heinandar
We do support here for forums that are hosted by the service  (SMF for Free) only.
Sounds like you are running the forum yourself - we won't be able to help you out here.
Here for support for self hosted forums:  http://www.simplemachines.org/community/index.php
« Last Edit: April 30, 2009, 06:30:44 pm by simply sibyl »

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
1192 Views
Last post September 27, 2007, 08:02:39 pm
by ~starwarsfz~
2 Replies
763 Views
Last post November 25, 2007, 01:08:29 pm
by Songbird
8 Replies
2533 Views
Last post November 26, 2008, 04:03:01 pm
by [JeReMy]
11 Replies
1651 Views
Last post May 12, 2009, 11:22:53 am
by simply sibyl
2 Replies
715 Views
Last post May 06, 2010, 06:13:30 pm
by Xxx9234