Hmmm. Okay, I guess there needs to be some type-casting in there.
On May 18, 2009, at 3:50 AM, Egill Sigurdur wrote:
Wow, thanks, but since I pretty much am a beginner in JS, could you
explain to me what’s wrong?
I get this working if I document.write oldEnough(“1301082102”,“5”),
but not without the quotes.
Bare numbers appear to JavaScript to be numbers first and foremost,
and in order to treat them like a string (to use substr()) you have to
“cast” them to a string using the toString() function. Wrapping them
in quotes also makes them into a string. I left this out of my
function, you could fix it there (and then it would work in both the
quoted and the unquoted form):
function oldEnough(ssn, intMinimumAge){
if (arguments.length < 2) return false;
var ssn = ssn.toString();
...
I can’t get this to work with this.value. Web Inpector always
says: “TypeError: Result of expression ‘str.substr’ [undefined] is
not a function.”
This should also be fixed, because we will cast the value to string
explicitly before trying to treat it as a string.
Yes, I wan’t to do this with somthing like Prototype, but I suck at
that.
I find Prototype to be much easier than vanilla JavaScript, because
you don’t have to worry about the plumbing as much. There was a 6
month learning curve similar to the Himalayas, but then it levels off,
I promise.
If I substr(4,6) something, I get six numbers, starting from the
fourth, so I just changed all the last substr numbers to 2, is that
right??
My mistake here as well. JavaScript has a substring() function and a
substr() function, and I used the wrong one. You are correct – the
syntax for substr() is (string, offsetStart, numberOfCharacters). The
syntax for substring() is (string, offsetStart, offsetEnd).
Walter
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options