Results 1 to 8 of 8

Thread: Alert maximum characters in textfield

  1. #1
    Join Date
    Feb 2010
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Alert maximum characters in textfield

    The alert should appear when the text is longer then the maximum characters for the choosen width.
    E.g.: choosen width is 15 cm, the max is 15 characters.

    Prototype

    Nearly ...
    But in stead of ???, I need the value of "var maxChars".

    Code:
    <script>
    <!--
    function checkchars(cur){
    var e = document.getElementById("FrogStyling_1_Size_Add");
    var maxChars = e.options[e.selectedIndex].value;
    var maxlength=maxChars
    
    if (cur.AddText.value.length>maxlength){
    alert("Please restrain your input to ??? or less characters !")
    return false
    }
    }
    //-->
    </script>


    Yam.
    Last edited by Yammaski; 02-17-2011 at 05:33 PM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Why don't you just use the maxlength attribute for inputs?
    Jeremy | jfein.net

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Agreed, but here's how to change your code:
    alert("Please restrain your input to "+maxChars+" or less characters !");

    Also, while the browsers may ignore this and continue working, you have a syntax error when an operation does not end in a semi-colon. For example:
    var maxlength=maxChars
    or
    return false
    and the alert, but I added it in my code above.

    Add a semi-colon ; to both and it will be valid.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. The Following User Says Thank You to djr33 For This Useful Post:

    Yammaski (02-18-2011)

  5. #4
    Join Date
    Feb 2010
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Thanks, it's working now.
    But I've 2 functions that I want to work with onsubmit event handler.
    I'll make another thread for this : "2 functions onsubmit event handler".


    Yam.

  6. #5
    Join Date
    Feb 2010
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Why don't you just use the maxlength attribute for inputs?
    Can you give a little more explanation, because I don't get it.

  7. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

  8. #7
    Join Date
    Feb 2010
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I think that isn't the solution I need here.
    It's the same textfield for different widths.

    Did you try my prototype ?

  9. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    THe reason this isn't working is because there's no element on the page with the ID "FrogStyling_1_Size_Add"

    Change:
    HTML Code:
    <select name="FrogStyling_1_Size_Add" onchange="this.form.submit()"> 
    To:
    HTML Code:
    <select id="FrogStyling_1_Size_Add" name="FrogStyling_1_Size_Add" onchange="this.form.submit()"> 
    Jeremy | jfein.net

  10. The Following User Says Thank You to Nile For This Useful Post:

    Yammaski (03-03-2011)

Bookmarks

Posting Permissions

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