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]
5 1764
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).
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..
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.
No problem, I solved it by defining a name for my form and then "document.form.element.value"...
Thank you very much!
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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 ) {
...
|
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...
|
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...
|
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.
...
|
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...
|
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?
|
by: pratimapaudel |
last post by:
function Showdiv()
{
var SelectStates = document.getElementById('Select1').value;
if(SelectStates ="3")
{
document.getElementById("div2").style.display = "block";
}
else
...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
| |