grizzly_beer grizzly_beer - 4 years ago 358
Javascript Question

javascript string length returning undefined

I cant seem to get a string length from a value in a form textfield
Here's the code for my function, its getting passed the parameter of the textfields name

function validate(thing)
{

var location = document.getElementById(thing);

var cardst = location.value;
window.alert (cardst);
cardst = String(cardst);
window.alert (cardst.lenght);


the first alert works, it alerts whatever I type into the textfield, but the second one is always undefined. As you can see I did cast it as a string but I get get undefined.. ANy ideas??

Answer Source

That would be because you misspelled length :-)

Use this instead:

cardst.length;   // <- 'th', not 'ht'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download