Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Expected error

Status
Not open for further replies.

akaballa123

Technical User
Apr 29, 2008
46
US
Hi,

I am creating a website, that carries both php and javascript code. However, I am having a problem with my javascript code, where I keep getting an object expected error one line 91. I tries to check to see if it is a php or javascript problem and then concluded that it is most likely related to javascript. Please correct me if im wrong.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<?php
include("mysqlConnection.php");

$result = @mysql_query('SELECT * FROM courses');
if (!$result) {
 exit('<p>Error performing query: ' . mysql_error() .
     '</p>');
}
$rst1 = @mysql_query('SELECT DISTINCT courseInstructor FROM courses WHERE courseInstructor <> ""');

include("mysqlConnClose.php")
?>
<meta name="generator">
<link type="text/css" rel="stylesheet" href="webLayout.css">
<title>Course Instructor Form</title>
</head>
<body>
<div class="cecbanner"><img src="cecBanner1.gif" width="600" height="60" border="0" alt="AS Trainings Tool"></div>

<script language="JavaScript" type="text/javascript">

function dateChk(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
          if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
             DateTemp = DateTemp + DateValue.substr(i,1);
          }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = '20' + DateValue.substr(0,2) + DateValue.substr(2,4) ; }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(0,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(4,2);
   if ((month < 1) || (month > 12)) {
      err = 22;
   }
   /* Validation of day*/
   day = DateValue.substr(6,2);
   if (day < 1) {
     err = 21;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; year = ""; month = ""; day = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field */

//Here is where the problem seems to occur
[Highlight]
   if (err == 0) {
      DateField.value = year + seperator + month + seperator + day;
   }
[/highlight]
   /* Error-message if err != 0 */
   else {
      alert("Date is incorrect! Please check you Date format and values!");
      DateField.select();
          DateField.focus();
   }
}


</script>
<form action="instructorSubmit.php" name="instructorForm" method="post" id="instructorForm">
<label>* Instructor Name</label> <select name="name" id="name" onchange="toggleHiddenElement()">
<?php
while ($arr = mysql_fetch_array($rst1)) {
 $value =  $arr['courseInstructor']  ;
 echo '<option >' .  $arr['courseInstructor']. '</option>';
 }
?>
<script language="JavaScript" type="text/javascript">
function toggleHiddenElement()
  {
     var myForm = window.document.instructorForm;
     var Cname = myForm.name;
     var Cnew = myForm.new;

  //There seems to be an error here...check it out!!
    if(Cname.value == 'other')
    {
        document.getElementById('otherName').style.display = 'block';

    }
    else
    {
        document.getElementById('otherName').style.display = 'none';
        Cnew.value = '';
    }

  }
</script>
<option value ='other'> Other </option> </select>
<br>
<div class="otherName" id="otherName">
<label>*New Name</label> <input type="text" name="new" id="new" />
</div>

<label>*Course Name</label> <select name="course" id="course"><?php
while ($row = mysql_fetch_array($result)) {
 $value =  $row['courseName']  ;
 echo '<option >' . $row['courseName'] .  '</option>';
 }
?></select>
<br>
<label>*Aprroximate Hours Spent on Preparing Course</label> <input type="text" name="hours" size="10" maxlength="10" />
<br>
<label>*Start Date (YYYY/MM/DD)</label> <input type="text" name="startDate" size="10" maxlength="10" onblur="dateChk(this)" />
<br>
<label>*End Date (YYYY/MM/DD)</label> <input type="text" name="endDate" size="10" maxlength="10" onblur="dateChk(this)" />
<input type="submit" class="buttons" value="Submit" >

</form>
</body>
</html>
 
This works fine for me. Did I miss something?

Code:
<html>

<script language="JavaScript" type="text/javascript">

function dateChk(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
          if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
             DateTemp = DateTemp + DateValue.substr(i,1);
          }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = '20' + DateValue.substr(0,2) + DateValue.substr(2,4) ; }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(0,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(4,2);
   if ((month < 1) || (month > 12)) {
      err = 22;
   }
   /* Validation of day*/
   day = DateValue.substr(6,2);
   if (day < 1) {
     err = 21;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; year = ""; month = ""; day = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field */

//Here is where the problem seems to occur

   if (err == 0) {
      DateField.value = year + seperator + month + seperator + day;
   }

   /* Error-message if err != 0 */
   else {
      alert("Date is incorrect! Please check you Date format and values!");
      DateField.select();
          DateField.focus();
   }
}


</script>

<body><form>
<label>*Aprroximate Hours Spent on Preparing Course</label> <input type="text" name="hours" size="10" maxlength="10" />
<br>
<label>*Start Date (YYYY/MM/DD)</label> <input type="text" name="startDate" size="10" maxlength="10" onblur="dateChk(this)" />
<br>
<label>*End Date (YYYY/MM/DD)</label> <input type="text" name="endDate" size="10" maxlength="10" onblur="dateChk(this)" />
<input type="submit" class="buttons" value="Submit" >

</form>
</body>

-----------------------------------------
I cannot be bought. Find leasing information at
 
Posy your client-side source, not server-side, and tell us what browser you see the error in.

P.S. How did you go with thread216-1497913 ? Did you resolve it in the end? You didn't say...

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I found the error in Internet Explorer. Mozilla seems to work fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top