Object expected; can't find it. Need another pair of eyes.

L

Laiverd.COM

Hi, In the following function I keep getting a 'Object expected at line 75
char 5' but for the life of me I cannot find the error. Maybe someone would
be so kin to have a look? I indicated the 'problem' line below in the
function.

function checkEmail(f){
// check for a valid emailadress
var field = f;
// alert(field.value);
var str = field.value;
if (str == ""){
errors += "[ " + field.name.toUpperCase() + " ] is een verplicht veld.\n";
} else if (str != "") {
// if the browser supports window.RegExp
if (window.RegExp) {
var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
var reg2str =
"^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
var reg1 = new RegExp(reg1str);
var reg2 = new RegExp(reg2str);
if (!reg1.test(str) && reg2.test(str)){
// emailadress is correct
return true;
} else {
errors += "[ " + str + " ] is een onjuist emailadres.\n";
////////////////////////////////////////////// THIS IS SUPPOSED TO BE A
PROBLEM
return false;
}
// if the browser does not support window.RegExp
} else {
if(str.indexOf("@") >= 0){
errors += "[ " + str + " ] is een onjuist emailadres.\n";
}
}

}
}

Thanks for lending me your eyes and wisdom.

John
 
K

kaeli

Hi, In the following function I keep getting a 'Object expected at line 75
char 5' but for the life of me I cannot find the error. Maybe someone would
be so kin to have a look? I indicated the 'problem' line below in the
function.

function checkEmail(f){

You never verify that the code that calls this function actually passes a
non-null string.
You should do that just for more stable code.
// check for a valid emailadress
var field = f;
// alert(field.value);
var str = field.value;

See, if someone passes you a null object, there won't be a value. This will
error out.
if (str == ""){
errors += "[ " + field.name.toUpperCase() + " ] is een verplicht veld.\n";

You do a concat ("+="), but I don't see "errors" defined anywhere. Is it
global? If not, you need
var errors = "";
at the beginning of this function.
} else {
errors += "[ " + str + " ] is een onjuist emailadres.\n";
////////////////////////////////////////////// THIS IS SUPPOSED TO BE A
PROBLEM

See above about the variable "errors".


--
--
~kaeli~
Synonym: the word you use in place of a word you can't
spell.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
L

Laiverd.COM

Well it did work untill I did not hardcode the names of the required fields
in javascript but instead created an array on the fly, like this

var requiredFields = new Array();
// get values for required fields from the form
var required = document.forms.contact.required.value;
requiredFields = required.split(",");
var errors = "";

As you see errors is initialised, and checkEmail() is called from a function
checkForm();

Just in case someone is willing to dive into all the code, here it is:

http://home.hccnet.nl/john.mulder/flash/temp/forms/example_form.html

Thanks again.

John
 
L

Laiverd.COM

Okay found out that it was a scope problem. I declared errors inside the function checkForm(), so it was local to that function and
not available in checkEmail().

Thanks for your time.

John

--
---------------------------------------------------------------------------------------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
---------------------------------------------------------------------------------------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
---------------------------------------------------------------------------------------
 
R

Richard Cornford

Laiverd.COM said:
Well it did work untill I did not hardcode the names of the required
fields in javascript but instead created an array on the fly, like
this

var requiredFields = new Array();
// get values for required fields from the form
var required = document.forms.contact.required.value;
requiredFields = required.split(",");
var errors = "";

As you see errors is initialised, and checkEmail() is
called from a function checkForm();

No, Kaeli was spot-on. You are defining - errors - as a local variable
in the - checkForm - function so it is not global, and then you are
using it in the - checkEmail - function as if it was global.

There are some other odd things in your code. You are using -
onSubmit="return checkForm(this);" - so the - checkForm - function is
being passed a reference to the function element as a parameter, but
instead of using it, it is repeatedly looking up the form in the -
documents.forms collection.

And building RegExp objects with the constructor using string literal
constants whenever you call the - checkEmail - function is a bit
over-the-top.

Richard.
 
L

Laiverd.COM

Thanks for the tips Andrew. It is appreciated.

John

--
---------------------------------------------------------------------------------------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
---------------------------------------------------------------------------------------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
---------------------------------------------------------------------------------------
 
L

Laiverd.COM

Richard,
Thanks for all your remarks. I'll definitely have a look into it.

John

--
---------------------------------------------------------------------------------------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
---------------------------------------------------------------------------------------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
---------------------------------------------------------------------------------------
 
L

Lee

Richard Cornford said:
There are some other odd things in your code. You are using -
onSubmit="return checkForm(this);" - so the - checkForm - function is
being passed a reference to the function element as a parameter, but

Quick! Somebody think of a clever line about confusing "form" and "function".
 
R

Richard Cornford

Lee said:
Richard Cornford said:
Quick! Somebody think of a clever line about confusing
"form" and "function".

<grin class="sheepish"/>

Isn't it a modernist aesthetic principle that form should follow
function?

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top