Exit function! Helpz

Discussion in 'JavaScript' started by Rex Romae, Jan 20, 2008.

  1. #1
    Hello guys!

    I've a problem, i wrote this script today, it controls the max lenght of chars of textarea and input text, but also if it advise me of the var of controls of chars is bigger of counter the script continue :(

    i must exit from function, but i don't know how...

    can you help me? thanks! ;)

    this is the script..

       <script language="JavaScript">
       function conta(){
       var chars = document.post.commento.value.length;
        if (chars > 255 ) {
         window.alert("Errore! Hai superato il limite di caratteri nel commento!");
     // NOW EXIT
    	}
       }
       function count(){
       var chars = document.post.titolo.value.length;
        if (chars > 50 ) {
         window.alert("Errore! Hai superato il limite di caratteri nel titolo!");
     // NOW EXIT
        }
       }
       </script>
    Code (markup):
     
    Rex Romae, Jan 20, 2008 IP
  2. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Buona notte:

    Use "return false".

    
    <script language="JavaScript">
       function conta(){
       var chars = document.post.commento.value.length;
        if (chars > 255 ) {
         window.alert("Errore! Hai superato il limite di caratteri nel commento!");
     // NOW EXIT
         return false;
    	}
       }
       function count(){
       var chars = document.post.titolo.value.length;
        if (chars > 50 ) {
         window.alert("Errore! Hai superato il limite di caratteri nel titolo!");
     // NOW EXIT
        return false;
        }
       }
       </script>
    
    Code (markup):
     
    Mike H., Jan 20, 2008 IP
  3. Rex Romae

    Rex Romae Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have try it, but the script contunue... :confused:
     
    Rex Romae, Jan 21, 2008 IP
  4. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Don't use "post" for the form name. Use a different name.

    Try this, otherwise, post the html for the form and explain exactly what you are trying to do.


    <script type="text/javascript">
    
       function conta(){
       var chars = document.forms[0].commento.value.length;
        if (chars > 255 ) 
             {
              alert("Errore! Hai superato il limite di caratteri nel commento!");    
              return false;
             }
        alert('Conta va bene');
        return true;
       }
    
       function count(){
       var chars = document.forms[0].titolo.value.length;
        if (chars > 50 )
            {
             alert("Errore! Hai superato il limite di caratteri nel titolo!");   
             return false;
            }
        alert('Conta va bene');
        return true;
       }
    
    
       </script>
    Code (markup):
     
    Mike H., Jan 21, 2008 IP
  5. Rex Romae

    Rex Romae Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks Mike H. I worked out with maxlenght's html tag and strlen's php function... :D

    but in this forum there is english man or italian??

    forza italia :D
     
    Rex Romae, Jan 21, 2008 IP
  6. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Di niente, prego. Sono studiano Italiano, il mio giovane amico. Hanno un bel giorno. Dio sorride su lei.
     
    Mike H., Jan 21, 2008 IP