Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-30-2008, 09:58 AM
aceofspades's Avatar
aceofspades aceofspades is offline
 
Join Date: Apr 2006
Posts: 306
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Word count mod - Ajax

Hey guys,

Is there a way to count the current amount of words typed in the message box and calculate how many characters remain untill the word limit is reached?

You can see an example here:
http://www.newgrounds.com/bbs/post/reply/914240

James
Reply With Quote
  #2  
Old 05-30-2008, 11:53 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

AJAX is not needed. JS is all that is required. I'm sure there are many tutorials on the net that will tell you have to get this counter.
Reply With Quote
  #3  
Old 05-31-2008, 09:59 AM
aceofspades's Avatar
aceofspades aceofspades is offline
 
Join Date: Apr 2006
Posts: 306
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi,

Ive been trying to do this but have come across some difficulties. First of all here is my code to count the characters:

Quote:
<html>
<head>
<title>Javascript Character Count</title>
<link href="basic.css" rel="stylesheet" type="text/css" />
<script language="JavaScript">

var running = false;

function start(){
running = true;
setTimeout('run();',500);
}

function run(){
document.ccform.display.value = document.ccform.text.value.length;
if(running)
setTimeout('run();',100);
}

function stop(){
running = false;
}

</script>
</head>
<body>
<h1>Javascript Character Counter</h1>
<form name="ccform">
<p><textarea name="text" rows="20" cols="100" onfocus="start();" onblur="stop();"></textarea></p>

<p><input type="text" name="display" /></p>
</form>

</body>
</html>
What i did was first impliment this into my editor_toolbar_off template, so that i had this:

Quote:
<div class="controlbar" style="text-align:$stylevar[left]">
<form name="ccform">
<textarea name="message" id="{$editorid}_textarea" rows="10" cols="60" style="width:$stylevar[messagewidth]; height:60px" tabindex="1">$newpost[message]</textarea>
<p><input type="text" name="display" /></p>
</form>

</div>
In bold is what i added and in italic is the var im going to change in the javascript example (from text to message)

Now i went to my editor_clientscript template and added the javascript with the rest of the javascript, this is what i added:

Quote:
<script language="JavaScript">

var running = false;

function start(){
running = true;
setTimeout('run();',500);
}

function run(){
document.ccform.display.value = document.ccform.message.value.length;
if(running)
setTimeout('run();',100);
}

function stop(){
running = false;
}

</script>
However what i am then left with is a box at the bottom that is meant to be displaying the number of words typed, but when i type numbers no numbers apprear or increase.

Can anyone tell me what the problem is? Ive tried to do it myself a few times but i really cant figure it out. I can provide any more information if it will help.

James

--------------- Added [DATE]1212254583[/DATE] at [TIME]1212254583[/TIME] ---------------

Ive just tested the code as it was originally posted and it works fine so im having a really hard time finding out why it isnt working. Ive also tried pasting the code at the top of the editor_toolbar_off template with the other javascript and it doesnt work there either :'(
Reply With Quote
  #4  
Old 06-01-2008, 10:02 AM
aceofspades's Avatar
aceofspades aceofspades is offline
 
Join Date: Apr 2006
Posts: 306
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Bump, i still cant figure this out and would really appreciate some help.

Regards,

James
Reply With Quote
  #5  
Old 06-02-2008, 02:12 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Remove the below in red:
Code:
<div class="controlbar" style="text-align:$stylevar[left]">
<form name="ccform">
    <textarea name="message" id="{$editorid}_textarea" rows="10" cols="60" style="width:$stylevar[messagewidth]; height:60px" tabindex="1">$newpost[message]</textarea>
<p><input type="text" name="display" /></p>
</form>
</div>
Note the changes that are in blue:
Code:
<script language="JavaScript">

var running = false;

function start(){
    running = true;
    setTimeout('run();',500);
}

function run(){
    document.vbform.display.value = document.vbform.message.value.length;
    if(running)
        setTimeout('run();',100);
}

function stop(){
    running = false;
}

</script>
You need to remove the ccform before there is already a form around the newthread area and so forth which is called 'vbform', so you don't need an additional form.
Reply With Quote
  #6  
Old 06-02-2008, 07:28 AM
aceofspades's Avatar
aceofspades aceofspades is offline
 
Join Date: Apr 2006
Posts: 306
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for the help. I made the adjustments that you suggested:

At the start of my editor_clientscript i have this javascript:

Quote:
<!-- EDITOR SCRIPTS -->
<script language="JavaScript">

var running = false;

function start(){
running = true;
setTimeout('run();',500);
}

function run(){
document.vbform.display.value = document.vbform.message.value.length;
if(running)
setTimeout('run();',100);
}

function stop(){
running = false;
}

</script>
....
In my editor_toolbar_off template i have this at the start:

Quote:
<!-- START NORMAL TEXT AREA -->
$vBeditTemplate[clientscript]

<div class="controlbar" style="text-align:$stylevar[left]">
<textarea name="message" id="{$editorid}_textarea" rows="10" cols="60" style="width:$stylevar[messagewidth]; height:60px" tabindex="1">$newpost[message]</textarea>
<p><input type="text" name="display" /></p>
</div>
Attached is the situation i have at the moment, i have the box for the numbers to display in, but when i type the javascript doesnt seem to register the letters and so the numbers dont go up.
Attached Images
File Type: bmp vb.bmp (555.6 KB, 15 views)
Reply With Quote
  #7  
Old 06-02-2008, 08:44 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I too have tried many variants of the code but it appears that due to the nature of the vBulletin text editor, it doesn't seem to register it as 'message' for the name but rather something else, or nothing at all. Unless you can find another way to call the actual text area of the editor then it won't be able to count the text.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:26 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03814 seconds
  • Memory Usage 2,253KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (1)postbit_attachment
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete