473,788 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: Object Expected error

TAM
Hi,

I have a simple JavaScript code that ensures that all the form fields
are filled and there is also a function that checks if the email is a
valid address. For some reason IE is giving "Object Expected" error on
the alert statement. The same code doesn't give an error in NN or
Opera or Mozilla or FireFox.

Can someone give me a clue as what could be wrong here?

Thanks,

joe

<script language = "JavaScript ">
function validate(){
if ((document.Solu tionEval.pwd.va lue ==
"")||(document. SolutionEval.pw d.value == null)){
alert("Please enter correct password")
document.Soluti onEval.pwd.focu s()
return false;
}
if (document.Solut ionEval.name.va lue == ""){
alert("Please enter your name")
document.Soluti onEval.name.foc us()
return false;
}
if (document.Solut ionEval.company .value == ""){
alert("Please enter your company name")
document.Soluti onEval.company. focus()
return false;
}
if (document.Solut ionEval.phone.v alue == ""){
alert("Please enter your phone number")
document.Soluti onEval.phone.fo cus()
return false;
}
if ((document.Solu tionEval.email. value ==
"")||(document. SolutionEval.em ail.value == null)){
alert("Please enter your email address")
document.Soluti onEval.email.fo cus()
return false;
}
/* check if the email address is valid */
if (echeck(documen t.SolutionEval. email.value)==f alse){
document.Soluti onEval.email.va lue=""
document.Soluti onEval.email.fo cus()
return false;
}
return true;
}

function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf (at)
var lstr=str.length
var ldot=str.indexO f(dot)
if (str.indexOf(at )==-1){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(at )==-1 || str.indexOf(at) ==0 ||
str.indexOf(at) ==lstr){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(do t)==-1 || str.indexOf(dot )==0 ||
str.indexOf(dot )==lstr){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(at ,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}

if (str.substring( lat-1,lat)==dot ||
str.substring(l at+1,lat+2)==do t){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(do t,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID") << This where IE gives error "Object
Expected"
return false
}

return true
}
</script>
Jul 23 '05 #1
1 2286
On 19 Aug 2004 11:15:56 -0700, TAM <gr*******@cana da.com> wrote:
I have a simple JavaScript code that ensures that all the form fields
are filled and there is also a function that checks if the email is a
valid address. For some reason IE is giving "Object Expected" error on
the alert statement. The same code doesn't give an error in NN or
Opera or Mozilla or FireFox.

Can someone give me a clue as what could be wrong here?
I can't see any problems with your code per se, but there are some
improvements to be made. The e-mail address validation, for instance, can
be greatly simplified with a regular expression.
<script language = "JavaScript ">
Valid HTML requires the type attribute. The language attribute is
deprecated and shouldn't be used any more.

<script type="text/javascript">
function validate(){
The first thing you could do here is save a reference to the form,
specifically, it's elements collection. It will save you having to type
out 'document.Solut ionEval.' every time:

var elem = document.forms['SolutionEval'].elements;

To access the password control below, you would write:

elem['pwd'].value
if ((document.Solu tionEval.pwd.va lue ==
"")||(document. SolutionEval.pw d.value == null)){
The value property will *never* be null. Testing for that condition is
pointless. Also, you can evaluate a string as a boolean (true/false). If
the string is empty (length zero), the expression will be false (see
below).
alert("Please enter correct password")
document.Soluti onEval.pwd.focu s()
return false;


Based on all of that, you could write the above as:

/* The ! (logical NOT) operator evaluates an expression
* as a boolean, then reverses the result.
*
* if(elem['pwd'].value) {
* // pwd contains at least one character
* } else {
* // pwd is empty
* }
*
* Add ! to the if expression (as I do below), and the first
* block will be executed if pwd is empty.
*/
if(!elem['pwd'].value) {
alert('Please enter a password.');
elem['pwd'].focus();
return false;
}

You can apply the same pattern to all of the other checks.

[snip]

As I said earlier, you can check an e-mail address with a regular
expression. The one below, taken from Dr Stockton's validation page is
greatly simplified, and will allow some invalid addresses, but it does
ensure basic form.

/^.+@.+\..+$/

You could change the last block in your validate function to:

if(!/^.+@.+\..+$/.test(elem['email'].value)) {
alert('Please enter a valid address.');
elem['email'].focus();
return false;
}

and delete echeck().

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2288
by: jsnX | last post by:
i want a function object that is a) initialized with an STL container foo b) will search foo for an object of type foo::value_type here is my code: ======================================================================== /* if we have a big list of things, and we went to check it * over and over for this or that thing, then we can use this * object to cache the list and consolidate queries of it.
1
2295
by: Franko | last post by:
I get the following error. Please help c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,38): error CS1001: Identifier expected c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,52): error CS1002: ; expected c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(7,19): error CS1519: Invalid token '(' in class, struct, or interface member declaration c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(9,2): error CS0116: A namespace does not...
11
44258
by: westplastic | last post by:
This one is driving me insane. The script works perfect on Firefox, but Internet Explorer keeps complaining about "Error Object Expected" and stuff like that. I've run it through Firefox's Java Console, and it comes back with no errors. Any pointers on this, would be much appreciated. <script type="text/javascript"> <!-- var p = new Array(0,0,0,0,0) var c = new Array(0,0,0,0,0,0,0,0,0)
3
4414
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing version numbers on anything. The errors come and go with no apparent rhyme or reason. We do not...
7
351
by: schdvir | last post by:
Hi I tried to compile a program and I got this error: tdagent.C: In constructor `tdagent::tdagent(simple_env*)': tdagent.C:13: error: no matching function for call to `actor::actor()' actor.H:28: note: candidates are: actor::actor(const actor&) actor.H:38: note: actor::actor(boost::numeric::ublas::vector<float, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > >)
0
2726
by: k1ckthem1dget | last post by:
I need to display the unsorted list of names and display the sorted list of names. My program is getting a bunch of errors though, and i dont know why. I am getting the following errors. 28: error: cannot convert `char (*)' to `int*' for argument `1' to `void showArray(int*, int)' 33: error: expected unqualified-id before "for" 33: error: expected constructor, destructor, or type conversion before '<' token 33: error: expected...
2
3246
by: k1ckthem1dget | last post by:
I need to display the unsorted list of names and display the sorted list of names. My program is getting a bunch of errors though, and i dont know why. I am getting the following errors. 28: error: cannot convert `char (*)' to `int*' for argument `1' to `void showArray(int*, int)' 33: error: expected unqualified-id before "for" 33: error: expected constructor, destructor, or type conversion before '<' token 33: error: expected...
1
3917
by: JOJO123 | last post by:
I got here in search of an answer to this Javascrpt question. I upgraded jave on XP Ie 7, acrobat 5.1 and suddenly can't open any pdf files on web sites using IE. I see u guys all say, this is a Javscript issue. but how do we, mere mortals who know nothing of anything about Java, scripts, etc, fix this? Is there a programm, does MS have any fix? is there any tweak like in the Registry, or whatever, how do I access anyihint java without in IE 7...
9
2457
by: beet | last post by:
Hi, I am really not good at c/c++. Some simple code.. #include <stdio.h> #include <stdlib.h> #include <math.h> #include "simlibdefs.h"
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.