By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,708 Members | 1,468 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,708 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_gr..._ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------
Jul 23 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
In article <41**********************@dreader2.news.tiscali.nl >,
sh******************@someserver.com enlightened us with...
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

Jul 23 '05 #2

P: n/a
On Thu, 5 Aug 2004 14:29:45 +0200, Laiverd.COM wrote:
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.
Did it occur to you that posting an error message
that mentions 'line 75' of a script embedded in a
58 line post is not that much use?
Thanks for lending me your eyes and wisdom.


I suggest you supply an URL*, unless you are
lucky enough to have one of the keen-eyed
Javascript guru's spot the error.

* <http://www.physci.org/codes/sscce.jsp>
[ Note that although that document is aimed more
at Java programmers, the same principles apply to
debugging Javascripts, HTML & CSS formatting.. ]

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #3

P: n/a
Yes that occured to me, and that's why I indicated the trouble line. Sorry
if that wasn't clear enough. I put up the page here:

http://home.hccnet.nl/john.mulder/fl...mple_form.html

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_gr..._ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------
Jul 23 '05 #4

P: n/a
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/fl...mple_form.html

Thanks again.

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_gr..._ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------
Jul 23 '05 #5

P: n/a
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_gr..._ugroup=*flash
---------------------------------------------------------------------------------------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
---------------------------------------------------------------------------------------
Jul 23 '05 #6

P: n/a
Laiverd.COM wrote:
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.
Jul 23 '05 #7

P: n/a
On Thu, 5 Aug 2004 16:26:58 +0200, Laiverd.COM wrote:
Yes that occured to me, and that's why I indicated the trouble line.
Yeahh.. I did notice that when I looked more
carefully at Kaeli's reply. D'oh!
..Sorry
if that wasn't clear enough.
Not for me, apparently. ;-)
..I put up the page here:

http://home.hccnet.nl/john.mulder/fl...mple_form.html


That will probably help sort the problem...

Note first though, that if the HTML does not
validate, your JS may not even be parsed properly.

Therefore it is important to get the HTML and
CSS valid before you start to worry too much
about the scripts. Checking..
<http://validator.w3.org/check?uri=http://home.hccnet.nl/john.mulder/flash/temp/forms/example_form.html>
indicates there are two problems with the HTML.
I doubt they are related to the JS bug, but
would advise fixing them in any case.

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #8

P: n/a
Thanks for the tips Andrew. It is appreciated.

John

--
---------------------------------------------------------------------------------------
RESOURCES
http://groups.google.com/advanced_gr..._ugroup=*flash
---------------------------------------------------------------------------------------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
---------------------------------------------------------------------------------------
Jul 23 '05 #9

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

John

--
---------------------------------------------------------------------------------------
RESOURCES
http://groups.google.com/advanced_gr..._ugroup=*flash
---------------------------------------------------------------------------------------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
---------------------------------------------------------------------------------------
Jul 23 '05 #10

P: n/a
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".

Jul 23 '05 #11

P: n/a
Lee wrote:
Richard Cornford said: <snip>
... passed a reference to the function element as a parameter,

<snip> 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.
Jul 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.