473,387 Members | 1,637 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,387 software developers and data experts.

Error:object expected

Good afternoon, I 've got the followin code to validate a form, and get the "error:object expected (line 171 char. 1, line 172, char 2)" even if i tried to solve it (parentheses, function syntax etc).
Can someone help, its a university homework that has to be delivered by Wednesday! (the first two buttons are name and surname in greek language, ignore the rest)
Here 's the code: (I've marked bold the lines that are the problem)

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Form validation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script language="Javascript">
// Η συνάρτηση αυτή καλείται για να καθορίσει την εμφάνιση ώρας και ημερομηνίας στο status bar
function dttm()
{
var days=new Array("Κυριακή","Δευτέρα","Τρίτη","Τετάρτη","Πέμπτ η","Παρασκευή","Σάββατο");
var mons=new Array("Ιανουάριος","Φεβρουάριος","Μάρτιος","Απρίλι ος","Μάιος","Ιούνιος", "Ιούλιος","Αύγουστος","Σεπτέμβριος","Οκτώβριος","Ν οέμβριος","Δεκέμβριος");
sys_date=new Date();
sys_dd=sys_date.getDate();
sys_mm=sys_date.getMonth();
sys_yyyy=sys_date.getYear();
sys_hours=sys_date.getHours();
sys_mins=sys_date.getMinutes();
sys_secs=sys_date.getSeconds();
sys_day=sys_date.getDay();
sys_w_day=days[sys_day];
sys_w_mon=mons[sys_mm];
disp_time=sys_hours+":"+sys_mins+":"+sys_secs;
window.status="Σήμερα είναι "+sys_w_day+" "+sys_w_mon+" "+sys_dd+","+sys_yyyy+". Η ώρα είναι: "+disp_time;
setTimeout("dttm()",1000);
}
</script>

<script type="text/javascript">
// Η συνάρτηση αυτή καλείται κάθε φορά που γίνεται κλικ στο πλήκτρο 'Submit'
function Validate() {
// Αν ισχύουν οι παρακάτω 3 προϋποθέσεις τότε η φόρμα συμπληρώθηκε σωστά
if (checkIfEmpty()==true && checkEmail()==true && checkPhone()==true) {
alert ('Η φόρμα συμπληρώθηκε σωστά!')
return true;
}
else
return false;
}

// Ελέγχει κατά πόσο υπάρχει έστω κι ένα πεδίο κενό
function checkIfEmpty() {
if(sirname.value=="" || name.value=="" || email.value=="" || telephone.value==""
|| username.value=="" || password.value=="" || passwordmore.value=="") {
window.alert("Παρακαλώ συμπληρώστε όλα τα πεδία!");
return(false);
}
else
return(true);
}

// Ελέγχει κατά πόσο συμπληρώθηκε σωστά το πεδίο 'email' (αν περιλαμβάνει τουλάχιστον τους χαρακτήρες '@' και '.')
function checkEmail() {
var i=0;
var pap = false;
var dot = false;
var emailExp = false;
var mail = email.value;
for(i=0;i<mail.length;i++) {
if(mail.charAt(i)=="@")
pap=true;
if(mail.charAt(i)==".")
dot=true;
if(mail.match(emailExp)=="/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/")
emailExp=true;
}

if(dot==true && pap==true && emailExp==true;)
return true;
else {
alert("Λάθος email!");
return false;
}
}

// Ελέγχει κατά πόσο συμπληρώθηκε σωστά το πεδίο 'telephone' (αν περιλαμβάνει αποκλειστικά αριθμητικούς χαρακτήρες)
function checkPhone() {
var i=0;
var okk=false;
var phone = telephone.value;
for(i=0;i<phone.length;i++) {
if(parseInt(phone.charAt(i))>=0 && parseInt(phone.charAt(i))=10 )
ok=true;
else {
window.alert("Λάθος τηλέφωνο!");
ok = false;
break;
}
}
return ok;
}
</script>
<meta name="Microsoft Border" content="t, default">
</head>

<BODY onLoad="dttm();"><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>

<p align="center"><font size="6" color="#666666"><strong>
</strong></font><br>
</p>
</td></tr><table dir="ltr" border="0" cellpadding="0" cellspacing="0" width="100%"><tr><!--msnavigation--><td valign="top">

<table border="0">
<tr>
<td height="51" colspan="2"><div align="center">
<p><b>Φόρμα καταχώρησης στοιχείων</b></p>
</div></td>
</tr>
<tr>
<td width="155" bgcolor="#9999FF">Όνομα:</td>
<td width="144"><input type="text" name="name"></td>
</tr>
<tr>
<td bgcolor="#9999FF">Επώνυμο:</td>
<td><input type="text" name="sirname"></td>
</tr>
<tr>
<td bgcolor="#9999FF">E-mail:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td bgcolor="#9999FF">Τηλέφωνο:</td>
<td><input type="text" name="telephone"></td>
</tr>
<tr>
<td bgcolor="#9999FF">Όνομα χρήστη(username):</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td bgcolor="#9999FF">Συνθηματικό(password):</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td bgcolor="#9999FF">Επανάληψη Συνθηματικού:</td>
<td><input type="password" name="passwordmore"></td>
</tr>
<tr>
<td bgcolor="#9999FF">Φύλλο:</td>
<td><p>
<label>
<input name="sex" type="radio" value="radio">
Άνδρας</label>
<br>
<label>
<input type="radio" name="sex" value="radio">
Γυναίκα</label>
<br>
</p></td>
</tr>
<tr>
<td bgcolor="#9999FF">Κατάσταση:</td>
<td><select name="situation">
<option>Ανήλικος</option>
<option>Άγαμος</option>
<option>Αρραβωνιασμένος</option>
<option>Παντρεμένος</option>
</select></td>
</tr>
<tr>
<td width="155" height="18" align="right" bgcolor="#bcf6f0" td> <hr> </td>
<td align="left" td bgcolor="#bcf6f0" width="144"> <hr> </td>
</tr>
<tr>
<td></td>
<td align="right"><a href="about_us.htm">About us</a>
</td>
</tr>
</table>
<p>
<input type="button" name="Button" value="Submit" onClick="Validate()">
<input type="button" name="Button" value="Reset" onClick="Validate()">

</p>
</BODY>

</html>[/HTML]
Jan 14 '08 #1
5 1764
acoder
16,027 Expert Mod 8TB
In checkIfEmpty() on line 44, you're checking sirname.value [sic], name.value, etc., but these are not global. You need to change this to, e.g. document.forms[formName].elements[elemName] where formName is the name of the form and elemName is the name of the form element. Alternatively, give the form elements IDs and access them using document.getElementById(theID).
Jan 15 '08 #2
So I have to give my form a name, and then give each button a name such as "form.button" so that the function can recongnize it globally?
It mustn't be this. After all, why is this smaller form that checks less things working?

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form validation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
// Η συνάρτηση αυτή καλείται κάθε φορά που γίνεται κλικ στο πλήκτρο 'Validate'
function Validate() {
// Αν ισχύουν οι παρακάτω 3 προϋποθέσεις τότε η φόρμα συμπληρώθηκε σωστά
if (checkIfEmpty()==true && checkEmail()==true && checkPhone()==true) {
alert ('Συγχαρητήρια! Η φόρμα συμπληρώθηκε σωστά!')
return true;
}
else
return false;
}

// Ελέγχει κατά πόσο υπάρχει έστω κι ένα πεδίο κενό
function checkIfEmpty() {
if(sirname.value=="" || name.value=="" || email.value=="" || telephone.value=="") {
window.alert("Παρακαλώ συμπληρώστε όλα τα πεδία!");
return(false);
}
else
return(true);
}

// Ελέγχει κατά πόσο συμπληρώθηκε σωστά το πεδίο 'email' (αν περιλαμβάνει τουλάχιστον τους χαρακτήρες '@' και '.')
function checkEmail() {
var i=0;
var pap = false;
var dot = false;
var mail = email.value;
for(i=0;i<mail.length;i++) {
if(mail.charAt(i)=="@")
pap=true;
if(mail.charAt(i)==".")
dot=true;
}

if(dot==true && pap==true)
return true;
else {
alert("Λάθος email!");
return false;
}
}

// Ελέγχει κατά πόσο συμπληρώθηκε σωστά το πεδίο 'telephone' (αν περιλαμβάνει αποκλειστικά αριθμητικούς χαρακτήρες)
function checkPhone() {
var i=0;
var okk=false;
var phone = telephone.value;
for(i=0;i<phone.length;i++) {
if(parseInt(phone.charAt(i))>=0 && parseInt(phone.charAt(i))<=9 )
ok=true;
else {
window.alert("Λάθος τηλέφωνο!");
ok = false;
break;
}
}
return ok;
}

</script>
<meta name="Microsoft Border" content="t, default">
</head>

<BODY><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>

<p align="center"><font size="6" color="#666666"><strong>
</strong></font><br>
</p>
</td></tr><table dir="ltr" border="0" cellpadding="0" cellspacing="0" width="100%"><tr><!--msnavigation--><td valign="top">

<table width="40%" border="0">
<tr>
<td height="51" colspan="2"><div align="center">
<p><b>Φόρμα καταχώρησης στοιχείων</b></p>
</div></td>
</tr>
<tr>
<td width="37%" bgcolor="#9999FF">Όνομα:</td>
<td width="65%"><input type="text" name="name"></td>
</tr>
<tr>
<td bgcolor="#9999FF">Επώνυμο:</td>
<td><input type="text" name="sirname"></td>
</tr>
<tr>
<td bgcolor="#9999FF">E-mail:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td bgcolor="#9999FF">Τηλέφωνο:</td>
<td><input type="text" name="telephone"></td>
</tr>
</table>
<p>
<input type="button" name="Button" value="Submit" onClick="Validate()">
</p>
</table></BODY>
</html>[/HTML]

Oh, and thank you very much friend, I get to know javascript better..
Jan 15 '08 #3
acoder
16,027 Expert Mod 8TB
So I have to give my form a name, and then give each button a name such as "form.button" so that the function can recongnize it globally?
The text fields already have names, so let's say your form was called "form1", then you would access the email field with document.forms["form1"].elements["email"].
It mustn't be this. After all, why is this smaller form that checks less things working?
No, it doesn't work. Test it on, say Firefox, and you will get an error.
Jan 15 '08 #4
No problem, I solved it by defining a name for my form and then "document.form.element.value"...

Thank you very much!
Jan 15 '08 #5
acoder
16,027 Expert Mod 8TB
No problem, I solved it by defining a name for my form and then "document.form.element.value"...
Yes, that's a different syntax for this. Glad you got it working.
Thank you very much!
You're welcome. Post again if you have any more questions.
Jan 15 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Erik-Jan Bakker | last post by:
Hello, I am stuck with a weird javascript problem.... ;-( Maybe it's somehting very simple, but I am really stuck in it, right now. What's the matter.... When place my website at a different...
11
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...
1
by: avanti | last post by:
HI, I have an ASP page with some Javascript code. The JS has several functions and only some of them work. Here is part of the code: <html xmlns="http://www.w3.org/1999/xhtml"> <head...
8
by: ipy2006 | last post by:
In my HTML I have, <input type="button" class="cartonsumkey" value="Sum Cartons" onclick="sumup(this);" /> In an external file that is called in Head area, I have, function sumup( o ) { ...
1
ashsa
by: ashsa | last post by:
Hi all, I am getting an error in my page saying that A Runtime Error has occured. Do you wish to debug ? Line : 509 Error : Object Expected Could the Line number indicated be of any use...
0
by: manojkm84 | last post by:
hi i have a very wierd error its like this i using .net 2005 c#....theres a webgrid in a page.....n when i try clicking on ny link in it it gives this error.. Line:317 Char:1...
5
by: Diego Ruiz | last post by:
Hi!! my english is not too good, but i'll try it I have a javascript code: function executeCommands(inputparms) { // Instantiate the Shell object and invoke its execute method. ...
7
by: juliejam | last post by:
Hello all, I am new here and hope some kind, smarter than me person can help. I am getting the error object expected with the following code: function click(e); here the error says it...
4
by: jiyesong | last post by:
I get the following error on a website at home, but not at work. Error: object expected Could it be an internet setting?
1
by: pratimapaudel | last post by:
function Showdiv() { var SelectStates = document.getElementById('Select1').value; if(SelectStates ="3") { document.getElementById("div2").style.display = "block"; } else ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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,...

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.