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 is required' when clicking submit button

Status
Not open for further replies.

motofzr1000

Technical User
Feb 15, 2007
5
BE
Hi,

recently, I downloaded a script to make MySQL database changes through a web interface written in php, and with some javascript. Everything works quite fine, except when I try to make changes to the database.

I'll explain how the script works... It outputs a table with all fields in a database, and I can add rows and delete them, so that part is working fine. But then I type something in the textfield of an existing table field, to make changes, the table row gets another color to show that a change has been made, and the 'Make changes' submit button gets enabled, which stays disabled if you don't touch the existing fields, so untill here still working fine. But it's when I try to submit the 'form' that I get a javascript error.

It's saying 'Object is required', and when I look at the lines of the error, it says this:

function datecheck(month,day,year){ //checks for illegal dates

obj = document.getElementById(month);
if(obj.value > 12 || obj.value < 1 || obj.value == "") {
alert('Enter valid month.');
return false;
}

So I have been trying to figure out what exactly the problem could be, but I can't find it. Have been trying to remove parts of the javascript, but then I got other errors, and it has gone from bad to worse. So I'm a bit stuck here... Is there anyone who can help me with this ? I guess it's more efficient if I post the code:

Code:
<?
#----------FUNCTIONS--------------------------------------
/*
	drawrow($primary, $value, $width, $maxlength, $type,$count,$name,$originalcolor,$column,$mode)
	
	parameter descriptions
	$primary: 		1 if column is a primary key.  used to hide id columns
	$value: 		field result
	$width: 		width of the textbox, based on the longest value return in that field
	$maxlength: 	the length of the field
	$type: 			datatype of field
	$count:			row number
	$name:			name of the field
	$originalcolor: background color of the row to return to if user starts to modify then resets back to default value	
	$column:		column number, based on total amount of fields
	$mode:			0 = normal display for editing , 1 = readonly for confirmation form, 2 = blank for adding a row
*/
#---------------------------------------------------------

#----------DECLARATIONS-----------------------------------
//set custom table variables here
$server 	= "localhost";
$database	= "DB";
$userid 	= "USER";
$password 	= "PASSWORD";
//$d_sort		= //hardcode default column to sort by - usually date
//the rest can be left blank
$subtitle 	= "";
$modinfo 	= "";
$errormes	= "";
$message	= "";
$fieldname	= "";
$fieldvalue = "";
$emails		= "";
$dates		= "";
#----------END DECLARATIONS-------------------------------

#----------POST AND GET RETRIEVALS------------------------
$order 		  = 	(isset($_GET['order'])) ? $_GET['order'] : $d_sort; //hardcode default column to sort by - usually date
//$direction    = 	(isset($_GET['direction'])) ? $_GET['direction'] : "ASC";  //sort direction
$action 	  = 	(isset($_POST['mode'])) ? $_POST['mode'] : "initial";
$confirmation =		(isset($_POST['confirmation'])) ? $_POST['confirmation'] : ""; //populated after form is posted with a change/add/delete
#----------END POST AND GET RETRIEVALS--------------------

//establish db connection
if(!($success = mysql_connect($server,$userid ,$password))){
$errormes = "Error connecting to server on $server";	
}
//select database
if(!mysql_select_db($database)){
$errormes = "Error selecting to database on $server";		
}

//table will be updated
if($confirmation){
$total = $_POST['total']; //total number of records being updated

$sql = "Select * from DB TABLE"; //get column names
$result = mysql_query($sql);

$num = mysql_num_fields($result);


	for($x=0;$x<($num);$x++){  //get all column information
	$fetchfield = mysql_fetch_field($result,$x);
	$fieldtitle[$x] = $fetchfield->name;
	$fieldprimary[$x] = $fetchfield->primary_key;
	$fieldtype[$x] = $fetchfield->type;
	}
	
		for($x=0;$x<$total;$x++){ //loop through rows to modify

		$set = "";
			for($y=0;$y<count($fieldtitle);$y++){ //loop through 
				if($fieldprimary[$y]) {
				} else {
					if($fieldtype[$y] == "datetime") {  //format date as format YYYY-MM-DD
					$fieldname  .= $fieldtitle[$y] . ",";
					$dateformat = $_POST['year' . $x] . "-" . $_POST['month' . $x] . "-" . $_POST['day' . $x] . " 00:00:00";
					$fieldvalue .= "'" . $dateformat . "',";
					$set .= " $fieldtitle[$y] = '" . $dateformat . "', ";
					} else {
					$fieldname  .= $fieldtitle[$y] . ",";
					$fieldval = $_POST[$fieldtitle[$y] . $x];
					$fieldvalue .= "'" . html_entity_decode(str_replace($escape,"''",$fieldval)) . "',";
					$set .= " $fieldtitle[$y] = '" . html_entity_decode(magicconversion($fieldval)) . "',";			
					}
				}
		
			}	
	
		$set 		= substr($set,0,(strlen($set)-1));
		$fieldname	= substr($fieldname,0,(strlen($fieldname)-1));
		$fieldvalue	= substr($fieldvalue,0,(strlen($fieldvalue)-1));

			if($action == "adding_confirmed") {
			$sql = "INSERT INTO DB TABLE ($fieldname) VALUES ($fieldvalue)";
			} else {
				if($action == "deleting_confirmed"){
				$sql = "DELETE FROM DB TABLE WHERE ID = " . $_POST['ID' . $x];
				} else {
				$sql = "UPDATE DB TABLE SET $set WHERE ID = " . $_POST['ID' . $x];
				}
			}
		
		//for DEMO version
		//echo "<div class=TOCHeader align=center>DEMO Version only - This will not modify table.  The following SQL was generated:</div>";
		//echo "<table class=demotable border=1 cellspacing=0 cellpadding=0><tr><td>$sql</td></tr></table>";
			if($result = mysql_query($sql)){
			$message  = "Table updated successfully.";
			} else {
			$errormes = "Unable to update table.";
			}
		
		}  // end for
		

} // end confirmation


$sql = "Select * from DB TABLE";
//get all records
$result = mysql_query($sql);

//get number of columns
$num = mysql_num_fields($result);
//get number of records, but set to 1 if just adding a record
$total = ($action == "adding") ? 1 : mysql_num_rows($result);

for($x=0;$x<($num);$x++){
	
//retrieve field statistics
$fetchfield 	= mysql_fetch_field($result);
//find length of data field
$maxlength[$x]  = mysql_field_len($result, $x);
//get column name
$fieldinfo[$x]  = $fetchfield->name;
//get primary key
$primary[$x] 	= $fetchfield->primary_key;
//get type
$type[$x] 		= $fetchfield->type;



//set width for text boxes
$width[50] = ($row[0]>0) ? $row[0]:2;

//handle sortpicture and link

	if($x==($order-2)){
	$arrow[$x+1] = ($direction == "DESC") ? "<img src='down.gif'>" : "<img src='up.gif'>";
	$sortdirection[$x+1] = ($direction == "DESC") ? "ASC" : "DESC";

	} else {
	$arrow[$x+1] = "";
	$sortdirection[$x+1] = "ASC";
	}
}


//check if modifying rows - for Confirm Changes page

if((!($action=="adding_confirmed")) && (!($action=="initial")) && (!($action=="deleting_confirmed"))){

$z = 0;
	for($x=0;$x<$total;$x++){
	//check for modified values - the hidden input 'rowmod + x' will be set to true for the changed row.
	$rowmod = ($action == "adding") ? ($_POST['add_rowmod0']) : ($_POST['rowmod' . $x]);
	
	
		if($rowmod == "true"){
		
		//fill $modinfo variable with new row information to post.  format = modinfo[rownumber][fieldname]
		$add = ($action == "adding") ? "add_" : "";
			for($y=0;$y<count($fieldinfo);$y++) {
				if(strtoupper($fieldinfo[$y]) == "DATE"){
				$modinfo[$z][$fieldinfo[$y]]  = $_POST[$add . 'month' . $x] . "/" . $_POST[$add . 'day' . $x] . "/" . $_POST[$add . 'year' . $x]; 
				} else {
				$modifiedcolumn = $fieldinfo[$y] . $x;
				$modinfo[$z][$fieldinfo[$y]] = str_replace($escape,"'",$_POST[$add . $modifiedcolumn]);
				}
			}
		$z++;
		}
	}
}  // end posting

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PAGE TITLE</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>

<body>
<div align="center"><img src="header.gif">
</div>
<p></p>
<? 

if($message) {
echo "<div class=success align=center>$message</div>";
} elseif($errormes){
echo "<div class=error align=center>$errormes</div>";
}


//will display the 'Confirm Changes' page
if($modinfo) {

$title = ($action == "adding") ? "Confirm Record to Add" : (($action=="deleting") ? "Confirm Records to <font style=\"color:#FF0000\">Delete</font>" : "Confirm Changes");
$addingparameter = ($action == "adding") ? "<input type=\"hidden\" id=\"mode\" name=\"mode\" value=\"adding_confirmed\">\n" : (($action=="deleting") ? "<input type=\"hidden\" id=\"mode\" name=\"mode\" value=\"deleting_confirmed\">\n" : "");

	for($x=0;$x<count($modinfo);$x++) {
		for($y=0;$y<count($fieldinfo);$y++){
		}
	}
?>
<br>
<form id=update name=update method=post action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" id="confirmation" name="confirmation" value="1">
<?=$addingparameter?>
<div class=boldheader align="center"><?=$title?></div>


<table cellpadding="0" cellspacing="0" border="2" style="border-collapse:collapse" bordercolor="#666666" width="100%">

<tr><td>
<table width=100% border="0" cellpadding="3" cellspacing="0">

<?
// show the rows to delete/modify/add

	//build the header row
	for($x=0;$x<count($fieldinfo);$x++){

		if($primary[$x]){
		} else {
		//datetime fields are parsed out into "mm/dd/yyyy" format
			if($type[$x]=="datetime"){
			echo "<td colspan=3 background='drop.gif' align=center class=rboldwhite>$fieldinfo[$x]</td>";
			} else {
			echo "<td background='drop.gif' align=center class=rboldwhite>$fieldinfo[$x]</td>";	
			}
	
		}	
	}	

	//display the rows
	for($x=0;$x<count($modinfo);$x++) {

  		if($x%2==0){
 		 $bgcolor = "#E5F4FF";
 		 } else {
 		 $bgcolor = "#C8E6FF";
  		}
	echo "<tr bgcolor=$bgcolor>";
		for($y=0;$y<count($fieldinfo);$y++){
		$value = ($modinfo[$x][$fieldinfo[$y]]) ? $modinfo[$x][$fieldinfo[$y]] : "";
		//calls drawrow() with 1 for the confirm parameter which displays it as readonly
		drawrow($primary[$y], $value, $width[$y], $maxlength[$y] , $type[$y],$x,$fieldinfo[$y],$bgcolor,$y,1);
		}
	
	echo "\n";
	}

?></table>
</td></tr></table>
<div align="center">
<br>
<input type="hidden" id="total" name="total" value="<?=$x?>">
<input type="button" onClick="window.location.href='<?=$_SERVER['PHP_SELF']?>'"  value="Go Back">
<input type="submit" value="Commit Changes" style="font-weight:bold;color:#009900">
</div>
<?
} else {
//not in an editing state, display the table initially
?>


<form id=update name=update method=post action="<?=$_SERVER['PHP_SELF']?>">

<br>
<input type="hidden" id="mode" name="mode" value="modifying">
<font class="footer">Click on the column headers to sort</font>
<table cellpadding="0" cellspacing="0" border="3" style="border-collapse:collapse" bordercolor="#999999" width="100%"><tr><td>
<Table width=100% border="0" cellpadding="3" cellspacing="0">
<tr><td colspan=<?=count($fieldinfo)+2?>  bgcolor="#5b5b5b">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
<td width="20%"><input type="button" class="clbuttonbig" onClick="window.location.href='<?=$_SERVER['PHP_SELF']?>#1'" value="Add New Record"></td>
<td width="60%" align="center"><input type="button" class="clbuttonbig" onClick="checkrow()" value="Make Changes" id="changestop" name= "changestop" disabled=true></td>
<td width="20%" align="right"><input type="button" class="clbuttonbig" onClick="deleterecords()" id="deleterecord" name="deleterecord" value="Delete Records" disabled=true></td>
</tr></table>


</td></tr>
<tr>
<?
//draws the header row of the edit table
for($x=0;$x<count($fieldinfo);$x++){

if($primary[$x]){
} else {
	//datetime fields are parsed out into "mm/dd/yyyy" format
	if($type[$x]=="datetime"){
	echo "<td colspan=3 background='drop.gif' align=center class=rboldwhite><a style=\"color:#FFFFFF\" href=\"" . $_SERVER['PHP_SELF'] . "?order=" . ($x + 1) . "&direction=" . $sortdirection[$x] . "\"> " . $fieldinfo[$x] . "</a>" . $arrow[$x] . "</td>";
	} else {
	echo "<td background='drop.gif' align=center class=rboldwhite><a style=\"color:#FFFFFF\"  href=\"" . $_SERVER['PHP_SELF'] . "?order=" . ($x + 1) . "&direction=" . $sortdirection[$x] . "\"> " . $fieldinfo[$x] . "</a>" . $arrow[$x] . "</td>";	
	}

}
}
echo "<td background='drop.gif' align=center class=rboldwhite>Delete<br>Record</td>";
?>
</tr>
<?
$z=0;
//list out all the fields in the result set - THIS IS THE MAIN INITIAL READOUT OF ALL ROWS
while ($rowobj = mysql_fetch_row($result)) {
  if($z%2==0){
  $bgcolor = "#CCCCCC";
  } else {
  $bgcolor = "#EEEEEE";
  } 


echo "<tr bgcolor=$bgcolor id=\"row" . $z . "\"><input type=hidden id=rowmod" . $z . " name=rowmod" . $z . " value=false>";
$colcount = 0;
	for($y=0;$y<count($fieldinfo);$y++){
	$value = ($rowobj[$y]) ? $rowobj[$y] : "";
//echo "drawrow(".$primary[$y].",".$value.",".$width[$y].",".$maxlength[$y].",".$type[$y].",".$z.",".$fieldinfo[$y].",".$bgcolor.",".$y.",0)<br>";
	drawrow($primary[$y], $value, $width[$y], $maxlength[$y] , $type[$y],$z,$fieldinfo[$y],$bgcolor,$y,0);
	}

echo "<td align=center><input type=\"checkbox\" id=\"delete$z\" name=\"delete$z\" onClick=\"deleterow($z,this,'$bgcolor')\"></td>";
echo "</tr>";

$z++;
}

?>
</Table>
</td></tr></table>
<? //only display bottom 'Make Changes' button if there are 30 or more records
if($z>29){ ?>
<br><div align="center"><input type="button" class="clbuttonbig" onClick="checkrow()" value="Make Changes" disabled="true" id="changesbottom" name="changesbottom"></div>
<? } ?>
</form>
<br>


<form id="add" name="add" action="<?=$_SERVER['PHP_SELF']?>" method="post" onSubmit="return datecheck('add_month0','add_day0','add_year0');">
<a name=#1></a>
<div class="boldheader" align="center">Add New Record</div>
<table cellpadding="2" cellspacing="2" border="3" style="border-collapse:collapse" bordercolor="#666666" width="100%">
<tr><td>
<Table width=100% border="0" cellpadding="2" cellspacing="2">
<tr>
<?
//draws the header row of the ADD table
for($x=0;$x<count($fieldinfo);$x++){

if($primary[$x]){
} else {
	//datetime fields are parsed out into "mm/dd/yyyy" format
	if($type[$x]=="datetime"){
	echo "<td colspan=3 background='drop.gif' align=center class=rboldwhite>" . $fieldinfo[$x] . "</td>";
	} else {
	echo "<td background='drop.gif' align=center class=rboldwhite>" . $fieldinfo[$x] . "</td>";	
	}

}
}
?>
</tr>

<tr style="background-color:#666666"><input type=hidden id="add_rowmod0" name="add_rowmod0" value=true>
<?
	for($y=0;$y<count($fieldinfo);$y++){
	//calls drawrow() with 2 for the mode parameter
	drawrow($primary[$y], "", $width[$y], $maxlength[$y] , $type[$y],0,"add_" . $fieldinfo[$y],"",$y,2);
	}	
?>
</tr>
</table>
</td></tr></table>
<br>
<div align="center">
<input name="addrecord" id="addrecord" type="submit"  class="clbuttonbig" value="Add Record"  disabled=true></div>
<input type=hidden name="mode" id="mode" value="adding">
</form>


<? } // END MODIFY OR DISPLAY IF ?>
</body>
<script language="javascript">

/* 
Javascript functions descriptions
checkrow() 		= checks for modified rows before posting form.
deleterecords()	= checks for 'delete records' checks before posting form.
checkvalue()	= handles modifications to rows and marks which columns/rows are being modified.
addrowcheck()	= verifies that atleast one text field in the add new row (in addition to the datetime field) is populated.
datecheck()		= makes sure date is valid.
deleterow()		= marks off rows which will be deleted.
*/

var modlist = new Array(<?=$z;?>); 
var rowchange = new Array(<?=$z;?>);
var rowdelete = new Array(<?=$z;?>);

	//prepopulates modlist, rochange, and rowdelete arrays with 0 values
   for (i=0; i < <?=$z;?>; i++) 
   { 
   rowchange[i] = 0;
   rowdelete[i] = 0;
       modlist[i] = new Array(<?=count($fieldinfo) - 1?>); 
       for (j=0; j < <?=count($fieldinfo) - 1?>; j++) 
       { 
       modlist[i][j] = 0; 
       } 
   } 


function checkrow(){ // checks rows to see if any have been modified before posting - called from Make Changes button
var modified = 0;
var dateproblems = "";
	for (var x=0;x<rowchange.length;x++){
		if(rowchange[x]){
		month =  "month" + x;
		day =  "day" + x;
		year = "year" + x;
			if(!datecheck(month,day,year)){
			dateproblems = "Please check all modified dates before attempting to make changes.";
			} else {
			obj = document.getElementById("rowmod" + x);
			obj.value = true;
			}
		modified = 1;
		}
	}

	if(modified && (!dateproblems)){
	obj = document.getElementById('update');
	obj.submit();
	} else {
		if(dateproblems){
		alert(dateproblems);
		} else {
		alert("No records have been modified.");		
		}	
	}

}

function deleterecords(){  //checks rows to see if any have been checked before posting - called from Delete Records button
var delchecked = 0;
	for(var x=0;x<rowdelete.length;x++){
		if(rowdelete[x]){
		obj = document.getElementById("rowmod" + x);
		obj.value = true;
		delchecked = 1;
		}
	}
	
	if(delchecked) {
	obj = document.getElementById('mode');
	obj.value = "deleting";
	obj = document.getElementById('update');
	obj.submit();
	} else {
	alert("No records have been checked.");
	}


}


function checkvalue(defaultval, textval, row, originalcolor, column) {  //checks if values in row are being modified or set back to default - called from any text box onKeyUp event

	//checks value against default
	if(!(defaultval == textval)){
	obj = document.getElementById("row" + row);
	obj.style.background = "#00FF00";
	//sets assigned row/column index to 1
	modlist[row][column] = 1;
	} else {
	modlist[row][column] = 0;
	}
	
	stillnew = 0;
	rowchange[row] = 0;
	//runs through the columns in the row to see if any are still in a modifed state
	for(x=0;x<modlist[row].length;x++){
		if(modlist[row][x]){
		rowchange[row] = 1;
		stillnew = 1;
		break;
		}
	}
	
	//if no columns have been modified (or text is edited back to its original state) backgroundcolor is reset
	if(!stillnew) {
	obj = document.getElementById("row" + row);
	obj.style.background = originalcolor;
	}
	
	editing = 0;
	//check if any row is still being modified in the entire table
	for (var x=0;x<rowchange.length;x++){
		if(rowchange[x]){
		editing = 1;
		break
		}
	}

	obj = document.getElementById("changestop");
	<?= ($z>29) ? "obj2 = document.getElementById(\"changesbottom\");" : ""; ?>

	//undisable 'Make Changes' buttons is something is still modified
	if(editing){
	obj.disabled = false;
	<?= ($z>29) ? "obj2.disabled = false;" : ""; ?>
	} else {
	obj.disabled = true;
	<?= ($z>29) ? "obj2.disabled = true;" : ""; ?>
	}
	
}

function addrowcheck(){ //checks all columns on the addrow section - at least one must be populated (including date) to add a row
<?
$arrayval = "";
//builds a javasacript array of field names
for($x=0;$x<count($fieldinfo);$x++){
	if(!$primary[$x]){
		if($type[$x]=="datetime"){
		$arrayval .= "\"add_month0\",\"add_day0\",\"add_year0\",";
		} else {
		$value = $fieldinfo[$x];
		$arrayval .= "\"add_" . $value . "0\",";
		}
	}
}
$arrayval = substr($arrayval,0,strlen($arrayval)-1);
?>
populate = 0;
	fieldname = new Array(<?=$arrayval?>);

	for(x=0;x<(modlist[0].length+2);x++){
	
	obj = document.getElementById(fieldname[x]);
		if(obj.value.length > 0){
		populate = 1;
		break;
		}
	}
		
	obj = document.getElementById("addrecord");
	if(populate){
	obj.disabled = false;
	} else {
	obj.disabled = true;
	}

}


function datecheck(month,day,year){ //checks for illegal dates

	obj = document.getElementById(month);
	if(obj.value > 12 || obj.value < 1 || obj.value == "") {
	alert('Enter valid month.');
	return false;
	}
	
	obj = document.getElementById(day);
	if(obj.value > 31 || obj.value < 1 || obj.value == "") {
	alert('Enter valid day.');
	return false;
	}
	
	obj = document.getElementById(year);
	if(obj.value > 2050 || obj.value < 1980 || obj.value == "") {
	alert('Enter valid year.');
	return false;
	}

return true;

}

function deleterow(row,checkbox,originalcolor){
editing = 0;
obj = document.getElementById("row" + row);

	if(checkbox.checked){
	obj.style.background = "#D71919";
	rowdelete[row] = 1;
	} else {
	obj.style.background = originalcolor;
	rowdelete[row] = 0;
	}
	
	
	
	for (var x=0;x<rowdelete.length;x++){
		if(rowdelete[x]){
		editing = 1;
		break
		}
	}
	
	obj = document.getElementById("deleterecord");
	if(editing){
	obj.disabled = false;
	} else {
	obj.disabled = true;
	}

}

</script>

</html>

<?
function drawrow($primary, $value, $width, $maxlength, $type,$count,$name,$originalcolor,$column,$mode){
	$add = "";
	//if this a confirmation page, disable editing
	if($mode == 1) {
	$edit = "readonly=true";
	$background = "background-color:#eaeaea";
	} elseif ($mode == 2) {
	$add = "add_";
	$edit = "";
	$background = "";	
	} else {
	$edit = "";
	$background = "";	
	}

//handle double quotes to dispaly correctly in input fields


global $colcount;
if($primary){
echo "<input type=\"hidden\" value=\"" . $value . "\" name=\"". $name . $count . "\">";
$colcount++;
} else {
	//draw row
	if($type == "datetime"){
	$m_num = (!($mode == 2)) ? date("m",strtotime($value)) : "";
	$d_num = (!($mode == 2)) ? date("d", strtotime($value)): "";
	$year  = (!($mode == 2)) ? date("Y", strtotime($value)): "";
		if($mode==0){
		$action =  "onkeyup=\"checkvalue('" . $m_num  . "',this.value, " . $count . ",'" . $originalcolor . "'," . $colcount . ");\""; 
		} elseif ($mode==2){
		$action =  "onkeyup=\"addrowcheck();\"";
		} else {
		$action = "";
		}
	echo "<td><input $edit $action type=\"text\" style=\"font-family: Courier New; font-size: 8pt;$background \" size=\"2\" maxlength=\"2\" name=\"" . $add . "month" . $count . "\" id=\"" . $add . "month" . $count . "\" value=\"" . $m_num . "\" ></td>";
	$colcount++;
		if($mode==0){
		$action =  "onkeyup=\"checkvalue('" . $d_num  . "',this.value, " . $count . ",'" . $originalcolor . "'," . $colcount . ");\""; 
		} elseif ($mode==2){
		$action =  "onkeyup=\"addrowcheck();\"";
		} else {
		$action = "";
		}
	echo "<td><input $edit $action type=\"text\" style=\"font-family: Courier New; font-size: 8pt;$background \" size=\"2\" maxlength=\"2\" name=\"" . $add . "day" . $count . "\" id=\"" . $add . "day" . $count . "\" value=\"" . $d_num . "\" ></td>";
	$colcount++;
		if($mode==0){
		$action =  "onkeyup=\"checkvalue('" . $year  . "',this.value, " . $count . ",'" . $originalcolor . "'," . $colcount . ");\""; 
		} elseif ($mode==2){
		$action =  "onkeyup=\"addrowcheck();\"";
		} else {
		$action = "";
		}
	echo "<td><input $edit $action type=\"text\" style=\"font-family: Courier New; font-size: 8pt;$background \" size=\"4\" maxlength=\"4\" name=\"" . $add . "year" . $count . "\" id=\"" . $add . "year" . $count . "\" value=\"" . $year . "\" ></td>";
	$colcount++;
	} else {
		if($mode==0){
		$action =  "onkeyup=\"checkvalue('" .  javascript_escape($value) . "',this.value, " . $count . ",'" . $originalcolor . "'," . $colcount . ")\""; 
		} elseif ($mode==2){
		$action =  "onkeyup=\"addrowcheck();\"";
		} else {
		$action = "";
		}
	echo "<td align=center style=normal><input $edit $action style=\"font-family: Courier New; font-size: 8pt;$background \" size=\"" . $width ."\" maxlength=\"" . $maxlength ."\" type=\"text\" name=\"" . $name . $count . "\" id=\"" . $name . $count . "\" value=\"" . single_display($value) . "\" ></td>\n";
	$colcount++;
	}
	echo "\n";

}


}

//functions to deal with escape characters

function javascript_escape($value) {
$value = str_replace("'","\'",$value);
$value = htmlentities($value);
return $value;
}

function single_display($value) {
	if(get_magic_quotes_gpc()){
	$value = str_replace("\'","'",$value);
	$value = str_replace('\"','"',$value);
	}
	
	$value = htmlentities($value);
	return $value;
}

function magicconversion($value){
	if(get_magic_quotes_gpc()){
	$value	= ereg_replace('\\\"','"',$value);
	$value	= ereg_replace("\\\'","''",$value);
	}
	return $value;
}


?>

cheers,

Jurgen
 
I have 2 suggestions. First, when you post a question in the Javascript forum, ALWAYS use the server output HTML, not the server-side code (PHP, ASP, Coldfusion, JSP).

Second, try using Firefox instead of IE to view the page. FF has a MUCH better Javascript debugger and should display the line the error is on, as well as which character in the line is causing the error.

Lee
 
I really don't know anything about PHP but I'm guessing that these 3 objects
Code:
document.getElementById('add_month0');
document.getElementById('add_day0');
document.getElementById('add_year0');

aren't defined in your code.

I'm guessing it's with your variable $count.

I can help you more if you show your code in a browser and copy the view source and post it here.

<.

 
thanks for the quick reply, and the tips...

I checked in Firefox, and the error console returns a lot of warnings, saying:

Warning: Expected ':' but found 'normal'. Declaration dropped.
Source File:
Line: 0

And the actual error message I get is:

Error: obj has no properties
Line: 259


Anyway, I also checked for the add_month, add_year, add_year, and I'm quite certain this has something to do with it. I downloaded this script, and changed the table names etc. to what I needed, but apparantly in the 'original' version, this script shows dates from a MySQL table, which I don't have in my DB. I've been trying to remove the datecheck part from the script earlier this week, but I only got more errors than before, so I don't know actually where to start.
 
Sorry, forgot to post the HTML output with it...

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PAGE TITLE</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>

<body>
<div align="center"><img src="header.gif">
</div>
<p></p>


<form id=update name=update method=post action="/table-edit.php">

<br>
<input type="hidden" id="mode" name="mode" value="modifying">
<font class="footer">Click on the column headers to sort</font>
<table cellpadding="0" cellspacing="0" border="3" style="border-collapse:collapse" bordercolor="#999999" width="100%"><tr><td>
<Table width=100% border="0" cellpadding="3" cellspacing="0">
<tr><td colspan=7  bgcolor="#5b5b5b">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
<td width="20%"><input type="button" class="clbuttonbig" onClick="window.location.href='/table-edit.php#1'" value="Add New Record"></td>
<td width="60%" align="center"><input type="button" class="clbuttonbig" onClick="checkrow()" value="Make Changes" id="changestop" name= "changestop" disabled=true></td>
<td width="20%" align="right"><input type="button" class="clbuttonbig" onClick="deleterecords()" id="deleterecord" name="deleterecord" value="Delete Records" disabled=true></td>
</tr></table>


</td></tr>
<tr>
<td background='drop.gif' align=center class=rboldwhite><a style="color:#FFFFFF"  href="/table-edit.php?order=2&direction=ASC"> project_naam</a></td><td background='drop.gif' align=center class=rboldwhite><a style="color:#FFFFFF"  href="/table-edit.php?order=3&direction=ASC"> project_inl</a></td><td background='drop.gif' align=center class=rboldwhite><a style="color:#FFFFFF"  href="/table-edit.php?order=4&direction=ASC"> project_location</a></td><td background='drop.gif' align=center class=rboldwhite><a style="color:#FFFFFF"  href="/table-edit.php?order=5&direction=ASC"> project_txt</a></td><td background='drop.gif' align=center class=rboldwhite>Delete<br>Record</td></tr>

<tr bgcolor=#CCCCCC id="row0"><input type=hidden id=rowmod0 name=rowmod0 value=false><input type="hidden" value="1" name="ID0"><td align=center style=normal><input  onkeyup="checkvalue('INLEIDING',this.value, 0,'#CCCCCC',1)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_naam0" id="project_naam0" value="project name" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Overzicht van verschillende horeca-projecten. Elk met hun eigenheid en hun specifiek karakter.',this.value, 0,'#CCCCCC',2)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_inl0" id="project_inl0" value="project short txt" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 0,'#CCCCCC',3)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_location0" id="project_location0" value="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 0,'#CCCCCC',4)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_txt0" id="project_txt0" value="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " ></td>

<td align=center><input type="checkbox" id="delete0" name="delete0" onClick="deleterow(0,this,'#CCCCCC')"></td></tr><tr bgcolor=#EEEEEE id="row1"><input type=hidden id=rowmod1 name=rowmod1 value=false><input type="hidden" value="2" name="ID1"><td align=center style=normal><input  onkeyup="checkvalue('Hangar 31',this.value, 1,'#EEEEEE',1)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_naam1" id="project_naam1" value="project name" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 1,'#EEEEEE',2)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_inl1" id="project_inl1" value="project short txt" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 1,'#EEEEEE',3)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_location1" id="project_location1" value="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 1,'#EEEEEE',4)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_txt1" id="project_txt1" value="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " ></td>

<td align=center><input type="checkbox" id="delete1" name="delete1" onClick="deleterow(1,this,'#EEEEEE')"></td></tr><tr bgcolor=#CCCCCC id="row2"><input type=hidden id=rowmod2 name=rowmod2 value=false><input type="hidden" value="3" name="ID2"><td align=center style=normal><input  onkeyup="checkvalue('Kok &amp; Ko',this.value, 2,'#CCCCCC',1)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_naam2" id="project_naam2" value="project name" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 2,'#CCCCCC',2)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_inl2" id="project_inl2" value="project short txt" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 2,'#CCCCCC',3)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_location2" id="project_location2" value="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 2,'#CCCCCC',4)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_txt2" id="project_txt2" value="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " ></td>

<td align=center><input type="checkbox" id="delete2" name="delete2" onClick="deleterow(2,this,'#CCCCCC')"></td></tr><tr bgcolor=#EEEEEE id="row3"><input type=hidden id=rowmod3 name=rowmod3 value=false><input type="hidden" value="4" name="ID3"><td align=center style=normal><input  onkeyup="checkvalue('Mezzanine',this.value, 3,'#EEEEEE',1)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_naam3" id="project_naam3" value="project name" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 3,'#EEEEEE',2)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_inl3" id="project_inl3" value="project short txt" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 3,'#EEEEEE',3)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_location3" id="project_location3" value="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 3,'#EEEEEE',4)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_txt3" id="project_txt3" value="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " ></td>

<td align=center><input type="checkbox" id="delete3" name="delete3" onClick="deleterow(3,this,'#EEEEEE')"></td></tr></Table>
</td></tr></table>

</form>
<br>


<form id="add" name="add" action="/table-edit.php" method="post" onSubmit="return datecheck('add_month0','add_day0','add_year0');">
<a name=#1></a>
<div class="boldheader" align="center">Add New Record</div>
<table cellpadding="2" cellspacing="2" border="3" style="border-collapse:collapse" bordercolor="#666666" width="100%">
<tr><td>
<Table width=100% border="0" cellpadding="2" cellspacing="2">
<tr>
<td background='drop.gif' align=center class=rboldwhite>project_naam</td><td background='drop.gif' align=center class=rboldwhite>project_inl</td><td background='drop.gif' align=center class=rboldwhite>project_location</td><td background='drop.gif' align=center class=rboldwhite>project_txt</td></tr>

<tr style="background-color:#666666"><input type=hidden id="add_rowmod0" name="add_rowmod0" value=true>
<input type="hidden" value="" name="add_ID0"><td align=center style=normal><input  onkeyup="addrowcheck();" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="add_project_naam0" id="add_project_naam0" value="" ></td>

<td align=center style=normal><input  onkeyup="addrowcheck();" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="add_project_inl0" id="add_project_inl0" value="" ></td>

<td align=center style=normal><input  onkeyup="addrowcheck();" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="add_project_location0" id="add_project_location0" value="" ></td>

<td align=center style=normal><input  onkeyup="addrowcheck();" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="add_project_txt0" id="add_project_txt0" value="" ></td>

</tr>
</table>
</td></tr></table>
<br>
<div align="center">
<input name="addrecord" id="addrecord" type="submit"  class="clbuttonbig" value="Add Record"  disabled=true></div>
<input type=hidden name="mode" id="mode" value="adding">

</form>


</body>
<script language="javascript">

/* 
Javascript functions descriptions
checkrow() 		= checks for modified rows before posting form.
deleterecords()	= checks for 'delete records' checks before posting form.
checkvalue()	= handles modifications to rows and marks which columns/rows are being modified.
addrowcheck()	= verifies that atleast one text field in the add new row (in addition to the datetime field) is populated.
datecheck()		= makes sure date is valid.
deleterow()		= marks off rows which will be deleted.
*/

var modlist = new Array(4); 
var rowchange = new Array(4);
var rowdelete = new Array(4);

	//prepopulates modlist, rochange, and rowdelete arrays with 0 values
   for (i=0; i < 4; i++) 
   { 
   rowchange[i] = 0;
   rowdelete[i] = 0;
       modlist[i] = new Array(4); 
       for (j=0; j < 4; j++) 
       { 
       modlist[i][j] = 0; 
       } 
   } 


function checkrow(){ // checks rows to see if any have been modified before posting - called from Make Changes button
var modified = 0;
var dateproblems = "";
	for (var x=0;x<rowchange.length;x++){
		if(rowchange[x]){
		month =  "month" + x;
		day =  "day" + x;
		year = "year" + x;
			if(!datecheck(month,day,year)){
			dateproblems = "Please check all modified dates before attempting to make changes.";
			} else {
			obj = document.getElementById("rowmod" + x);
			obj.value = true;
			}
		modified = 1;
		}
	}

	if(modified && (!dateproblems)){
	obj = document.getElementById('update');
	obj.submit();
	} else {
		if(dateproblems){
		alert(dateproblems);
		} else {
		alert("No records have been modified.");		
		}	
	}

}

function deleterecords(){  //checks rows to see if any have been checked before posting - called from Delete Records button
var delchecked = 0;
	for(var x=0;x<rowdelete.length;x++){
		if(rowdelete[x]){
		obj = document.getElementById("rowmod" + x);
		obj.value = true;
		delchecked = 1;
		}
	}
	
	if(delchecked) {
	obj = document.getElementById('mode');
	obj.value = "deleting";
	obj = document.getElementById('update');
	obj.submit();
	} else {
	alert("No records have been checked.");
	}


}


function checkvalue(defaultval, textval, row, originalcolor, column) {  //checks if values in row are being modified or set back to default - called from any text box onKeyUp event

	//checks value against default
	if(!(defaultval == textval)){
	obj = document.getElementById("row" + row);
	obj.style.background = "#00FF00";
	//sets assigned row/column index to 1
	modlist[row][column] = 1;
	} else {
	modlist[row][column] = 0;
	}
	
	stillnew = 0;
	rowchange[row] = 0;
	//runs through the columns in the row to see if any are still in a modifed state
	for(x=0;x<modlist[row].length;x++){
		if(modlist[row][x]){
		rowchange[row] = 1;
		stillnew = 1;
		break;
		}
	}
	
	//if no columns have been modified (or text is edited back to its original state) backgroundcolor is reset
	if(!stillnew) {
	obj = document.getElementById("row" + row);
	obj.style.background = originalcolor;
	}
	
	editing = 0;
	//check if any row is still being modified in the entire table
	for (var x=0;x<rowchange.length;x++){
		if(rowchange[x]){
		editing = 1;
		break
		}
	}

	obj = document.getElementById("changestop");
	
	//undisable 'Make Changes' buttons is something is still modified
	if(editing){
	obj.disabled = false;
		} else {
	obj.disabled = true;
		}
	
}

function addrowcheck(){ //checks all columns on the addrow section - at least one must be populated (including date) to add a row
populate = 0;
	fieldname = new Array("add_project_naam0","add_project_inl0","add_project_location0","add_project_txt0");

	for(x=0;x<(modlist[0].length+2);x++){
	
	obj = document.getElementById(fieldname[x]);
		if(obj.value.length > 0){
		populate = 1;
		break;
		}
	}
		
	obj = document.getElementById("addrecord");
	if(populate){
	obj.disabled = false;
	} else {
	obj.disabled = true;
	}

}


function datecheck(month,day,year){ //checks for illegal dates

	obj = document.getElementById(month);
	if(obj.value > 12 || obj.value < 1 || obj.value == "") {
	alert('Enter valid month.');
	return false;
	}
	
	obj = document.getElementById(day);
	if(obj.value > 31 || obj.value < 1 || obj.value == "") {
	alert('Enter valid day.');
	return false;
	}
	
	obj = document.getElementById(year);
	if(obj.value > 2050 || obj.value < 1980 || obj.value == "") {
	alert('Enter valid year.');
	return false;
	}

return true;

}

function deleterow(row,checkbox,originalcolor){
editing = 0;
obj = document.getElementById("row" + row);

	if(checkbox.checked){
	obj.style.background = "#D71919";
	rowdelete[row] = 1;
	} else {
	obj.style.background = originalcolor;
	rowdelete[row] = 0;
	}
	
	
	
	for (var x=0;x<rowdelete.length;x++){
		if(rowdelete[x]){
		editing = 1;
		break
		}
	}
	
	obj = document.getElementById("deleterecord");
	if(editing){
	obj.disabled = false;
	} else {
	obj.disabled = true;
	}

}

</script>

</html>
 
You have no elements with the ID of add_month0, add_day0, or add_year0.

Code:
<form id="add" name="add" action="/table-edit.php" method="post" onSubmit="return datecheck('add_month0','add_day0','add_year0');">

Code:
function datecheck(month,day,year){ //checks for illegal dates

    obj = document.getElementById(month);
    if(obj.value > 12 || obj.value < 1 || obj.value == "") {
    alert('Enter valid month.');
    return false;
    }
    
    obj = document.getElementById(day);
    if(obj.value > 31 || obj.value < 1 || obj.value == "") {
    alert('Enter valid day.');
    return false;
    }
    
    obj = document.getElementById(year);
    if(obj.value > 2050 || obj.value < 1980 || obj.value == "") {
    alert('Enter valid year.');
    return false;
    }

return true;
}

Lee
 
Yeah like I said above (way way way above), and trollacious said you have no elements named
'add_month0'
'add_day0'
'add_year0'

For now, since you have no elements to reference, just take out the onsubmit function

Code:
<form id="add" name="add" action="/table-edit.php" method="post" [!]onSubmit="return datecheck('add_month0','add_day0','add_year0');"[/!]>

Just delete what I have highlighted and see if your code works for what you currently have.

<.

 
Now I removed the datecheck function from the code, since I don't need it anyway, and there was another function, which checked for modified dates, and I removed this as well, but I think I removed too much. the page returns no errors anymore, but it doesn't submit the changes. Actually nothing happens when I click on 'Make Changes'.

The other function I removed was named checkrow, which checks for modified fields and also modified date fields. I thought if I removed it, it would post the data whatsoever. Apparantly not...

Anyway, here's the browser HTML output:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PAGE TITLE</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>

<body>
<div align="center"><img src="header.gif">
</div>
<p></p>


<form id=update name=update method=post action="/table-edit.php">

<br>
<input type="hidden" id="mode" name="mode" value="modifying">
<font class="footer">Click on the column headers to sort</font>
<table cellpadding="0" cellspacing="0" border="3" style="border-collapse:collapse" bordercolor="#999999" width="100%"><tr><td>
<Table width=100% border="0" cellpadding="3" cellspacing="0">
<tr><td colspan=7  bgcolor="#5b5b5b">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
<td width="20%"><input type="button" class="clbuttonbig" onClick="window.location.href='/table-edit.php#1'" value="Add New Record"></td>
<td width="60%" align="center"><input type="button" class="clbuttonbig" value="Make Changes" id="changestop" name= "changestop" disabled=true></td>
<td width="20%" align="right"><input type="button" class="clbuttonbig" onClick="deleterecords()" id="deleterecord" name="deleterecord" value="Delete Records" disabled=true></td>
</tr></table>


</td></tr>
<tr>
<td background='drop.gif' align=center class=rboldwhite><a style="color:#FFFFFF"  href="/table-edit.php?order=2&direction=ASC"> project_naam</a></td><td background='drop.gif' align=center class=rboldwhite><a style="color:#FFFFFF"  href="/table-edit.php?order=3&direction=ASC"> project_inl</a></td><td background='drop.gif' align=center class=rboldwhite><a style="color:#FFFFFF"  href="/table-edit.php?order=4&direction=ASC"> project_location</a></td><td background='drop.gif' align=center class=rboldwhite><a style="color:#FFFFFF"  href="/table-edit.php?order=5&direction=ASC"> project_txt</a></td><td background='drop.gif' align=center class=rboldwhite>Delete<br>Record</td></tr>

<tr bgcolor=#CCCCCC id="row0"><input type=hidden id=rowmod0 name=rowmod0 value=false><input type="hidden" value="1" name="ID0"><td align=center style=normal><input  onkeyup="checkvalue('INLEIDING',this.value, 0,'#CCCCCC',1)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_naam0" id="project_naam0" value="project name" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Overzicht van verschillende horeca-projecten. Elk met hun eigenheid en hun specifiek karakter.',this.value, 0,'#CCCCCC',2)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_inl0" id="project_inl0" value="project txt" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 0,'#CCCCCC',3)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_location0" id="project_location0" value="project txt 2" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 0,'#CCCCCC',4)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_txt0" id="project_txt0" value="project txt 3" ></td>

<td align=center><input type="checkbox" id="delete0" name="delete0" onClick="deleterow(0,this,'#CCCCCC')"></td></tr><tr bgcolor=#EEEEEE id="row1"><input type=hidden id=rowmod1 name=rowmod1 value=false><input type="hidden" value="2" name="ID1"><td align=center style=normal><input  onkeyup="checkvalue('Hangar 31',this.value, 1,'#EEEEEE',1)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_naam1" id="project_naam1" value="project name" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 1,'#EEEEEE',2)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_inl1" id="project_inl1" value="project txt" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 1,'#EEEEEE',3)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_location1" id="project_location1" value="project txt 2" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 1,'#EEEEEE',4)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_txt1" id="project_txt1" value="project txt 3" ></td>

<td align=center><input type="checkbox" id="delete1" name="delete1" onClick="deleterow(1,this,'#EEEEEE')"></td></tr><tr bgcolor=#CCCCCC id="row2"><input type=hidden id=rowmod2 name=rowmod2 value=false><input type="hidden" value="3" name="ID2"><td align=center style=normal><input  onkeyup="checkvalue('Kok &amp; Ko',this.value, 2,'#CCCCCC',1)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_naam2" id="project_naam2" value="project name" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 2,'#CCCCCC',2)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_inl2" id="project_inl2" value="project txt" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 2,'#CCCCCC',3)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_location2" id="project_location2" value="project txt 2" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 2,'#CCCCCC',4)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_txt2" id="project_txt2" value="project txt 3" ></td>

<td align=center><input type="checkbox" id="delete2" name="delete2" onClick="deleterow(2,this,'#CCCCCC')"></td></tr><tr bgcolor=#EEEEEE id="row3"><input type=hidden id=rowmod3 name=rowmod3 value=false><input type="hidden" value="4" name="ID3"><td align=center style=normal><input  onkeyup="checkvalue('Mezzanine',this.value, 3,'#EEEEEE',1)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_naam3" id="project_naam3" value="project name" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 3,'#EEEEEE',2)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_inl3" id="project_inl3" value="project txt" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('',this.value, 3,'#EEEEEE',3)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="project_location3" id="project_location3" value="project txt 2" ></td>

<td align=center style=normal><input  onkeyup="checkvalue('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',this.value, 3,'#EEEEEE',4)" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="project_txt3" id="project_txt3" value="project txt 3" ></td>

<td align=center><input type="checkbox" id="delete3" name="delete3" onClick="deleterow(3,this,'#EEEEEE')"></td></tr></Table>
</td></tr></table>

</form>
<br>


<form id="add" name="add" action="/table-edit.php" method="post">
<a name=#1></a>
<div class="boldheader" align="center">Add New Record</div>
<table cellpadding="2" cellspacing="2" border="3" style="border-collapse:collapse" bordercolor="#666666" width="100%">
<tr><td>
<Table width=100% border="0" cellpadding="2" cellspacing="2">
<tr>
<td background='drop.gif' align=center class=rboldwhite>project_naam</td><td background='drop.gif' align=center class=rboldwhite>project_inl</td><td background='drop.gif' align=center class=rboldwhite>project_location</td><td background='drop.gif' align=center class=rboldwhite>project_txt</td></tr>

<tr style="background-color:#666666"><input type=hidden id="add_rowmod0" name="add_rowmod0" value=true>
<input type="hidden" value="" name="add_ID0"><td align=center style=normal><input  onkeyup="addrowcheck();" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="add_project_naam0" id="add_project_naam0" value="" ></td>

<td align=center style=normal><input  onkeyup="addrowcheck();" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="add_project_inl0" id="add_project_inl0" value="" ></td>

<td align=center style=normal><input  onkeyup="addrowcheck();" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="255" type="text" name="add_project_location0" id="add_project_location0" value="" ></td>

<td align=center style=normal><input  onkeyup="addrowcheck();" style="font-family: Courier New; font-size: 8pt; " size="" maxlength="16777215" type="text" name="add_project_txt0" id="add_project_txt0" value="" ></td>

</tr>
</table>
</td></tr></table>
<br>
<div align="center">
<input name="addrecord" id="addrecord" type="submit"  class="clbuttonbig" value="Add Record"  disabled=true></div>
<input type=hidden name="mode" id="mode" value="adding">

</form>


</body>
<script language="javascript">

/* 
Javascript functions descriptions
checkrow() 		= checks for modified rows before posting form.
deleterecords()	= checks for 'delete records' checks before posting form.
checkvalue()	= handles modifications to rows and marks which columns/rows are being modified.
addrowcheck()	= verifies that atleast one text field in the add new row (in addition to the datetime field) is populated.
datecheck()		= makes sure date is valid.
deleterow()		= marks off rows which will be deleted.
*/

var modlist = new Array(4); 
var rowchange = new Array(4);
var rowdelete = new Array(4);

	//prepopulates modlist, rochange, and rowdelete arrays with 0 values
   for (i=0; i < 4; i++) 
   { 
   rowchange[i] = 0;
   rowdelete[i] = 0;
       modlist[i] = new Array(4); 
       for (j=0; j < 4; j++) 
       { 
       modlist[i][j] = 0; 
       } 
   } 

function deleterecords(){  //checks rows to see if any have been checked before posting - called from Delete Records button
var delchecked = 0;
	for(var x=0;x<rowdelete.length;x++){
		if(rowdelete[x]){
		obj = document.getElementById("rowmod" + x);
		obj.value = true;
		delchecked = 1;
		}
	}
	
	if(delchecked) {
	obj = document.getElementById('mode');
	obj.value = "deleting";
	obj = document.getElementById('update');
	obj.submit();
	} else {
	alert("No records have been checked.");
	}


}


function checkvalue(defaultval, textval, row, originalcolor, column) {  //checks if values in row are being modified or set back to default - called from any text box onKeyUp event

	//checks value against default
	if(!(defaultval == textval)){
	obj = document.getElementById("row" + row);
	obj.style.background = "#00FF00";
	//sets assigned row/column index to 1
	modlist[row][column] = 1;
	} else {
	modlist[row][column] = 0;
	}
	
	stillnew = 0;
	rowchange[row] = 0;
	//runs through the columns in the row to see if any are still in a modifed state
	for(x=0;x<modlist[row].length;x++){
		if(modlist[row][x]){
		rowchange[row] = 1;
		stillnew = 1;
		break;
		}
	}
	
	//if no columns have been modified (or text is edited back to its original state) backgroundcolor is reset
	if(!stillnew) {
	obj = document.getElementById("row" + row);
	obj.style.background = originalcolor;
	}
	
	editing = 0;
	//check if any row is still being modified in the entire table
	for (var x=0;x<rowchange.length;x++){
		if(rowchange[x]){
		editing = 1;
		break
		}
	}

	obj = document.getElementById("changestop");
	
	//undisable 'Make Changes' buttons is something is still modified
	if(editing){
	obj.disabled = false;
		} else {
	obj.disabled = true;
		}
	
}

function addrowcheck(){ //checks all columns on the addrow section - at least one must be populated (including date) to add a row
populate = 0;
	fieldname = new Array("add_ID0");

	for(x=0;x<(modlist[0].length+2);x++){
	
	obj = document.getElementById(fieldname[x]);
		if(obj.value.length > 0){
		populate = 1;
		break;
		}
	}
		
	obj = document.getElementById("addrecord");
	if(populate){
	obj.disabled = false;
	} else {
	obj.disabled = true;
	}

}

function deleterow(row,checkbox,originalcolor){
editing = 0;
obj = document.getElementById("row" + row);

	if(checkbox.checked){
	obj.style.background = "#D71919";
	rowdelete[row] = 1;
	} else {
	obj.style.background = originalcolor;
	rowdelete[row] = 0;
	}
	
	
	
	for (var x=0;x<rowdelete.length;x++){
		if(rowdelete[x]){
		editing = 1;
		break
		}
	}
	
	obj = document.getElementById("deleterecord");
	if(editing){
	obj.disabled = false;
	} else {
	obj.disabled = true;
	}

}

</script>

</html>
 
Here is your button:

Code:
<td width="60%" align="center"><input type="button" class="clbuttonbig" value="Make Changes" id="changestop" name= "changestop" disabled=true></td>

What is it supposed to do? Right now there are no event handlers on this button, it won't do anything.

<.

 
Object is required" can also refer to missing functions or other objects besides what monksnake found in his first post.

The error message provided by FireFox was much more helpful than wading through all that server-side code in the first example, and it only confirmed what had already been stated.

Your example obviously doesn't need ALL that HTML, and I'd recommend that you just post the relevant parts in other questions you ask. Most people won't even bother looking over all that code. What I did was copy and paste the code into Textpad and do a search for the function calls.

Lee
 
Probably not the best workaround, but I got it working...

I replaced

Code:
<form id="add" name="add" action="<?=$_SERVER['PHP_SELF']?>" method="post" onSubmit="return datecheck('add_month0','add_day0','add_year0');">

with:


Code:
<form id="add" name="add" action="<?=$_SERVER['PHP_SELF']?>" method="post">

and replaced:

Code:
function datecheck(month,day,year){ //checks for illegal dates

	obj = document.getElementById(month);
	if(obj.value > 12 || obj.value < 1 || obj.value == "") {
	alert('Enter valid month.');
	return false;
	}
	
	obj = document.getElementById(day);
	if(obj.value > 31 || obj.value < 1 || obj.value == "") {
	alert('Enter valid day.');
	return false;
	}
	
	obj = document.getElementById(year);
	if(obj.value > 2050 || obj.value < 1980 || obj.value == "") {
	alert('Enter valid year.');
	return false;
	}

return true;

}


with:

Code:
function datecheck(month,day,year){ //checks for illegal dates
return true;

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top