View Full Version : :: what am i doing wrong here? ::
babelfish
09-02-2002, 12:27 PM
why isnt the below code working? im using onblur='validateasemail()' to call it
function validatasemail() {
var thefield = formname.fieldname.value;
if (thefield.indexof("@") ==-1) {
alert('Please enter a proper email address, for example: name@domain.com')
}
}
can you not point me to a working alternative - im trying to learn jscript by trial and error :)
joh6nn
09-02-2002, 12:33 PM
"formname.fieldname.value;"
do you have the document object in there?
babelfish
09-02-2002, 12:37 PM
erm...
well - my code looks like this:
function validatasemail() {
var thefield = window.document._contactform.contactEmailAddress.value;
alert(thefield);
if (thefield.indexof("@") ==-1) {
alert('Please enter a proper email address, for example: name@domain.com')
}
}
when this is working i want to make it so that the script dynimically finds the form name and field name - but i cant get this working :(
joh6nn
09-02-2002, 12:42 PM
variables with underscores at the start aren't good ideas in javascript. they have special meaning. i couldn't say what it is, without looking it up, but i know it's there. _contactform should be changed.
the real problem though, that i didn't notice before, is here: thefield.indexof("@")
the 'o' has to be capitalized: indexOf()
babelfish
09-02-2002, 12:46 PM
lmao - i just figured that out about 20 seconds ago !
and im using dreamweaver that even has color coded syntax and i dint notice - oh FFS @ case sensitive :rolleyes:
now, all i need to do is grab the formname and fieldname dynamically (hint hint) :)
and i cant change the formname as its dynamically created in lotus notes :( my boss wont let me use php or asp and all our other dbase stuff runs in notes anyway
anyway tghis is what i have atm:
function validatasemail() {
var thefield = document._contactform.contactEmailAddress.value;
alert(thefield);
if ((thefield.indexOf("@") ==-1) || (thefield.indexOf(".") ==-1)) {
alert('Please enter a proper email address, for example: name@domain.com')
}
}
joh6nn
09-02-2002, 01:22 PM
onblur="validatasemail(this);"
function validatasemail(that) {
var thefield = that.value;
if ((thefield.indexOf("@") ==-1) || (thefield.indexOf(".") ==-1)) {
alert('Please enter a proper email address, for example: name@domain.com')
}
}
you mean like that?
ps, if you want it, somewhere i have a RegEx that validates an email address.
mordred
09-02-2002, 01:27 PM
Originally posted by joh6nn
variables with underscores at the start aren't good ideas in javascript. they have special meaning. i couldn't say what it is, without looking it up, but i know it's there. _contactform should be changed.
I do also feel uncomfortable when I have to deal with underscores at the beginning of variable's names, but are they really a problem? I only now that variables mustn't start with numbers, since that is ambigious.
On the other hand, were talking about DOM identifiers. So it would be best to look at the naming policies for name/id attributes for the used HTML standard. I'm just too lazy now...
var _ = "hello";
alert(_);
seems to work just fine. :)
joh6nn
09-02-2002, 01:35 PM
i stand corrected. i've just looked it up in the Guide, and apparently, it's the $ that you're encouraged to stay away from, not the _ . the $ is supposed to be used by programs that generate code, like MM, so the guide suggests avoiding it.
babelfish
09-02-2002, 01:54 PM
thanks guys!
strange thing is that version isnt very different from one i tried that didnt work - doh! :rolleyes:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.