SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Location
    Southeast Michigan
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    String Length function not working properly

    I have a function that's supposed to check the length of a Tweet input box and make display a message depending on weather the max characters are exceeded or not. But when i run it, the if else loop only runs the "else" part no matter how many characters have been typed.

    My Code:

    Code JavaScript:
    function checkTweet() {
    	var maxLength = 140;
    	var button = document.getElementById('submit');
    	var tweetLength = document.getElementById("name");
     
    	button.onclick = function () {
    		if (tweetLength.length <= maxLength) {
    			alert("Tweet Submitted");
    		} else {
    			alert("You have to many characters!");
    		}
    	};
    }

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if an element with the id 'name' is an input field, you probably want to read the length of its value, the text it contains.

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Location
    Southeast Michigan
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You! That did the trick.


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
  •