TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-23-2009, 09:20 PM   #1 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default Accessing Lenght of a string in Javascript with jQuery

I have been learning some jQuery and things are shaping up pretty well. But i have hit my head on the following thing.

In this bit of code that works fine there is a part where i am trying to get the lenght of the 'altVar' variable but nothing seem to happen.

The only thing i can think of is that 'altVar' is no longer a object and donīt have a lenght property ?

am i thinking in the wrong direction here or is the late hours making my brain a little fuzzy.

I turning to you JavaScript gurus here on the site.
Have a look at this code. It all works well except that i want the code in the IF statement only to be TRUE if the lenght of the string taken from the alt attribute of the targeted element is more then 0.

The return from 'var strLen = altVar.lenght' is 'undefined' ?
i donīt get it. Why ?

I should mention im a newbie in the JavaScript realm :)

If you need any other info to help me out, just tell me what you need :)

Thanks in advance.

Code:
$("a.menuLink").mouseenter(function() {
 // Animate
 $(this).animate({paddingLeft:"+20px"}, { duration: 400 });

 // Get data out of elements alt attribute.
 // also find out string lenght
	
 var altVar = $(this).attr('alt');
 var strLen = altVar.lenght;
 
 // show status div only if string
 // is more then 0 in lenght
 if(strLen > 0)
 {
  $('#statusDiv').show();
  $('#statusDiv').html(altVar);
 }
		
});
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 09-23-2009, 09:24 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

There is no lenght property, the correct English word (and indeed the correct property name) would be length
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
EyeDentify (09-23-2009)
Old 09-23-2009, 09:28 PM   #3 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
There is no lenght property, the correct English word (and indeed the correct property name) would be length
Ow.... do i feel stupid :)

Ofcourse that would be the problem :)

And the late hours here in sweden :)

Thx, Salathe your a godsend :)
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 09-23-2009, 09:41 PM   #4 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

Edit: Now the code works perfectly the way i want :)

Note to self :) property is 'length' not 'lenght'
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 09-23-2009, 10:00 PM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by EyeDentify View Post
Thx, Salathe your a godsend :)
We all make super-simple mistakes from time to time and often it takes someone else to spot them.
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easily Format JSON using PHP and Interpret using Javascript Wildhoney Advanced PHP Programming 13 02-01-2013 11:05 AM
Basics or jQuery? devnull Javascript, AJAX, E4X 20 08-12-2009 03:12 PM
javascript question allworknoplay Javascript, AJAX, E4X 15 04-23-2009 09:30 AM
array elements into variables and values Dave Absolute Beginners 7 06-20-2008 01:56 PM
Part 1: Getting Started with Javascript and DOM Wildhoney Javascript, AJAX, E4X 6 11-08-2007 12:52 PM


All times are GMT. The time now is 09:31 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design