akaballa123
Technical User
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.
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>