Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2003
    Location
    scotland, edinburgh
    Posts
    176
    Thanks
    5
    Thanked 1 Time in 1 Post

    Minimum words in text area

    I have seen a few javascripts that count the number of characters / letters like this http://www.felgall.com/jstip42.htm but what i would like is like a countdown where once you have writen more than 500 words it will let you post the item
    some advice or help would be great thanks

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    try this
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    script>
    function 
    lung(f,k){
    n=10;//number of max allowed characters
    var = new String();
    k.split('');
    for(
    i=0;i<n;i++){+= s[i]}
    if(
    s.length>=n){f.elements['txt'].value=v;
    f.elements['lun'].value n-v.length;
    }
    else{
    f.elements['lun'].value n-s.length;}
    }
    </script>
    </head>
    <body>
    insert max. 10 characters
    <form>
      <textarea name="txt" cols="30" rows="2" onkeyup="lung(this.form,this.value)"onblur="lung(this.form,this.value)"></textarea>
      <br>
      available characters left: 
      <input name="lun" type="text" class="hideform" value="10" readonly="readonly">
    </form>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    You seem to have the word count script, so what is wanted
    is simply

    function checkwords (numberofwords) {
    if (numberofwords <500) {
    alert ("You must write 500 words before the form can be submitted");
    return false;
    }
    return true
    }

    <form onSubmit= "checkwords(numberofwords)".....>

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ...and for counting words (the previous code counts characters) try this:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    script>
    function 
    lung(f,k){
    n=10;//number of max allowed words
    var = new String();
    k.split(' ');
    for(
    i=0;i<n;i++){+= (s[i]+' ')}
    if(
    s.length>=n+1){f.elements['txt'].value=v;
    f.elements['lun'].value n+1-v.length;
    }
    else{
    f.elements['lun'].value n+1-s.length;}
    if(
    f.elements['lun'].value==-9){f.elements['lun'].value=0}
    }
    </script>
    </head>
    <body>
    insert max. 10 words
    <form>
      <textarea name="txt" cols="30" rows="2" onkeyup="lung(this.form,this.value)"onblur="lung(this.form,this.value)"></textarea>
      <br>
      available number of words left: 
      <input name="lun" type="text" class="hideform" value="10" readonly="readonly">
    </form>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •