SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: String Length

  1. #1
    SitePoint Guru brent5392's Avatar
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    String Length

    Ok, my problem is the script below. Im new to javascript so it makes little sense to me. I managed to write the below, but it doesnt work...

    Code:
    <script type="text/javascript">
    function checklength()
    {
    	var text = document.form[0].element[2].value;
    	if(text.length => 5)
    	{
    		alert("String Too Long! It will be reduced to 5 charactes when you submit");
    	}
    
    }
    </script>
    On the form element I have

    Code:
    onkeypress="checklength()"
    As I said, I am new to javascript so I dont understand why this isnt working...
    Can someone explain why?

    ~Brent~
    PHP | MySQL | (X)HTML | CSS

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You mean
    Code:
    document.forms[0].elements[2].value
    not
    Code:
    document.form[0].element[2].value
    Here's a handy reference: http://www.javascriptkit.com/jsref/
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •