php vs. javascript

  • r3ynz_t4nz
  • Born
  • Born
  • r3ynz_t4nz
  • Posts: 1

Post 3+ Months Ago

can someone help me., and translate or generate this javascript code in php..,

Code: [ Select ]
<html>
<head>
<title> </title>
</head>
<body>

<form name="my_form" method="post">

<textarea onKeyPress=check_length(my_form);
         onKeyDown=check_length(my_form);
        name="my_text"
        rows=4 cols=30>
        
</textarea>
<br>
<input size=1 value=50 name=text_num> Characters Left

</form>

<script language=JavaScript>

function check_length(my_form){

maxLen = 50;

     if ( my_form.my_text.value.length >= maxLen ) {

         var msg = "You have reached your maximum limit of characters allowed";
        
         alert(msg);

         my_form.my_text.value = my_form.my_text.value.substring(0, maxLen);

     }

     else {

            my_form.text_num.value = maxLen - my_form.my_text.value.length;
    
     }

}

</script>

</body>
</html>
  1. <html>
  2. <head>
  3. <title> </title>
  4. </head>
  5. <body>
  6. <form name="my_form" method="post">
  7. <textarea onKeyPress=check_length(my_form);
  8.          onKeyDown=check_length(my_form);
  9.         name="my_text"
  10.         rows=4 cols=30>
  11.         
  12. </textarea>
  13. <br>
  14. <input size=1 value=50 name=text_num> Characters Left
  15. </form>
  16. <script language=JavaScript>
  17. function check_length(my_form){
  18. maxLen = 50;
  19.      if ( my_form.my_text.value.length >= maxLen ) {
  20.          var msg = "You have reached your maximum limit of characters allowed";
  21.         
  22.          alert(msg);
  23.          my_form.my_text.value = my_form.my_text.value.substring(0, maxLen);
  24.      }
  25.      else {
  26.             my_form.text_num.value = maxLen - my_form.my_text.value.length;
  27.     
  28.      }
  29. }
  30. </script>
  31. </body>
  32. </html>


thanks.,.
reynz
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Code: [ Select ]
function check_length($max,$string){
if(strlen($string) > $max){
    echo "You have passed the maximum amount of characters";
    $string = substr($string,0,$max);
}
else{
    echo "There are " . $max - strlen($string) . " characters left";
}
}
  1. function check_length($max,$string){
  2. if(strlen($string) > $max){
  3.     echo "You have passed the maximum amount of characters";
  4.     $string = substr($string,0,$max);
  5. }
  6. else{
  7.     echo "There are " . $max - strlen($string) . " characters left";
  8. }
  9. }

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 83 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.