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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |