Most of the developers on my current project use a (to me) strange way to check for empty strings in ECMAScript:
if (theString.length == 0)
// string is empty
I ... |
I want to check the size of the string entered in a text box.
what am I missing?
var com = document.getElementById("comment").value;
if(com.lenght <= 100){
alert("good");
} else {
alert("bad");
}
|
I'm doing something like this:
alert(document.getElementById('cardNumber').value);
And it alerts cardNumber value. But I need in it's lenght:
alert(document.getElementById('cardNumber').value.lenght);
undefined
Why?
|
I am in need of a JavaScript function which can take a value and pad it to a given length (I need spaces, but anything would do). I found this: |
In the popup window, selText does have the value "great," but the length is always undefined. Something related with the encoding of the string?
var selText = document.getSelection(); //suppose "great" is selected
alert( ...
|
What I can use in "Microsoft JScript" instead length() with string. String class does not have Method length() or I did't find. What a best way to get string length?
|
i'm implementing a charcounter in the UI, so a user can see how many characters are left for input.
To count, i use this simple function:
function typerCount(source, layerID)
{
outPanel ...
|
|
When iterating over a string or array (or anything else with a length property), I've always used a loop like this:
var foo = [...];
var i;
for(i=0; i<foo.length; i++) {
...
|
|
|
|
This is a prime example of what Javascript should not be used for. What you want is to truncate the data BEFORE it leaves the server. This saves your visitor, and you, from transferring more data then is required. Not sure about you, but I'd do a whole lot to reduce my bandwidth costs! |
|
|
|
function validate_form ( ) { valid = true; if (document.forms[0].elements[0].value == "Search our inventory.." ) { alert ("Please enter a search term."); valid = false; } if (document.forms[0].elements[0].string.length < ... |
|
|
hi, Suppose i have a string in variable, var textContent. It can have as low as 1 to even 200 words. What i want to know if there is a way to check the length each of the words in the string? so that lets say, if a word http:/www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com exists then i want to use alert to show message that ... |
|
|
I'm learning JavaScript and I'm getting an "undefined" error. I understand the reason behind this is the length of a string is 250 characters. My question is, does a space count as a character. In other words how many characters are in this sentence... SitePoint is cool 17 or 15? Thanks, Palmer |