473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
11 1585
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
1
by: Ldaled | last post by:
Okay, I had a previous post called reading an XML document. Since this post I have revised my code and got it to work. Now, Like Derek had mentioned in answer to my previous post, I am getting an...
4
by: Jon | last post by:
Hello all, can someone please be my second pair of eyes! I'm getting the above error at line: for(int i = 0; i <= dlstScope.Items.Count-1; i++). My code's below: (dlstScope is a nested dlstScope...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
6
by: learning | last post by:
I am trying to learn STL but got stuck in for_each(). What I intend to do in the following is to make a list with each element as a string. add the string elements to the list until it has 10...
4
by: =?Utf-8?B?RXJpY2E=?= | last post by:
I am trying to dynamically create a javascript link. But, I get the following error: BC32017: Comma, ')', or a valid expression continuation expected. Here is the line I try creating the...
5
by: virtualadepts | last post by:
I have code here that explains my object oriented design model. I've been reading about other design models from what is documented on wikipedia about the key book on the subject:...
6
by: Rafe | last post by:
Forgive me if I mangle any terminology here, but please correct me if I do... I have an object which acts exactly like a string as long as I stay in Python land. However, I am using the object...
23
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.