Bluehost.com Web Hosting $6.95

form character counter help

This is a discussion on form character counter help within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi One and all, Question is the away to do what the Java Script below is doing but in PHP ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-05-2005
Joker7
 
Posts: n/a
Default form character counter help

Hi One and all,
Question is the away to do what the Java Script below is doing but in PHP as
I don't like using Java Script if I can help it.
I need a way to count and show the user of the form how many characters are
left.

Cheers
Chris

<script language = "Javascript">
function taLimit() {
var txt=event.srcElement;
if (txt.value.length==txt.maxLength*1) return false;
}

function taCount(t_count) {
var txt=event.srcElement;
if (txt.value.length>txt.maxLength*1)
txt.value=txt.value.substring(0,txt.maxLength*1);
if (t_count) t_count.innerText=txt.maxLength-txt.value.length;
}
</script>

Maximum Number of characters is 255.<br>
<TEXTAREA onkeypress="return taLimit()" onkeyup="return taCount(myCounter)"
name=Description rows=7 wrap=physical cols=40 maxLength="255"></TEXTAREA>
<br><br><SPAN id=myCounter>255</SPAN> characters remaining


Reply With Quote
  #2 (permalink)  
Old 11-05-2005
Janwillem Borleffs
 
Posts: n/a
Default Re: form character counter help

Joker7 wrote:
> Question is the away to do what the Java Script below is doing but in
> PHP as I don't like using Java Script if I can help it.
> I need a way to count and show the user of the form how many
> characters are left.
>


JavaScript = (most of the cases) client side & PHP = server side;

The stuff you are doing with JavaScript can only be done by PHP by sending
regular calls to the server, where PHP validates the input. These calls need
to be triggered by JavaScript, so apart from the fact that the server will
be called frequently, this solution will not be very practical.

The best thing you can do is put both the JavaScript and server side PHP
validation in place. When JavaScript is enabled on the client, it does its
stuff and the PHP script on the server will complement the validation.


JW



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:22 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0