Jump to content

IE error: 'document.guestbookform.txtName' is null or not an object


yobri

Recommended Posts

Although this PHP-driven guestbook form works fine and processes all data with the majority of predominant Web browsers (well namely IE, FF, Opera and Safari), it creates an error in IE with the yellow exclamation icon and the word Done in the bottom lower left corner status.

 

The error states:

 

Line: 90

Char: 2

Error: 'document.guestbookform.txtName' is null or not an object

Code: 0

URL: http://*****/guestbook.php

 

Although this *may* not be caused by the PHP code here, I was hoping that someone here may know what is causing this error in any case (which appears to possibly be a JS function, in all likelihood). The code is below:

 

Thank you for any help that you can provide. It's much appreciated.

 

<?php
//ob_clean();

$host = "localhost";
$user = "*****";
$pass = "*****";
$db = "*****";

mysql_connect($host, $user, $pass) OR die ("Could not connect to the server.");
mysql_select_db($db) OR die("Could not connect to the database.");
       
$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);

if (!isset($_POST['txtName'])) {

    $query = "SELECT id, name, message, DATE_FORMAT(date, '%M %D, %Y') as newdate FROM guests ORDER BY id DESC";

    $result = mysql_query($query);
     
    while ($row = mysql_fetch_object($result)) {

?>

<link href="http://*****.css" rel="stylesheet" type="text/css">

<body bgcolor="#cecece" link="#660033" alink="#660033" vlink="#660033">
<p>
	<div class="guestbook">
		<?php echo $row->message = nl2br($row->message); ?><br /><br />
		<strong>Posted by <?php echo $row->name; ?></strong><br />
	</div>
	<div class="gbmini">
		<?php echo $row->newdate; ?>   |   <strong><a href="#sign" style="text-decoration:none">SIGN OUR GUESTBOOK</a></strong>
	</div>
	<br />
	<div align="center"><img src="http://*****.gif" align="middle" height="3" width="100%" /></div>
	<!--div align="center" class="gbline">~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~</div-->
</p>
<?php
         
    }
     
?>
<script language="javascript">

<!--

function dataCheck() {

var the_name = document.guestbookform.txtName.value;
var the_message = document.guestbookform.txtMessage.value;

var baseMsg = "";
var endMsg = "\n\nThank you.";

var noNameMsg = baseMsg+"Please input your name in the NAME field"+endMsg;
var noMessageMsg = baseMsg+"Please input a message in the YOUR MESSAGE field"+endMsg;

if (the_name == "") { alert(noNameMsg); return false }
if (the_message == "") { alert(noMessageMsg); return false }

document.guestbookform.action.value = "submit";
document.guestbookform.submit();

}

//-->

</script>
<?php

echo "<script language='javascript'>dataCheck();</script>";

?>
<p class="guestbook">To sign our guestbook, please type your name(s) in the <strong>Name(s)</strong> field and a brief message in the <strong>Your message</strong> field, and then press the <strong>Send</strong> button. <br /><br />Thank you!</p>
<form method="post" onsubmit="dataCheck()" name="guestbookform" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

    <p><label for="txtName" class="guestbook">Name(s):</label><br />
    <input type="text" title="Enter your name" name="txtName" maxlength="50" size="20" /></p>

    <p><label for="txtMessage" class="guestbook">Your message:</label><br />
<!--input type="text" title="Enter your message" name="txtMessage" maxlength="255" size="35" /-->
    <textarea title="Enter your message" name="txtMessage" cols="28" rows="3"></textarea></p>
     
    <p><label title="Send your message" class="guestbook"></label>
    <input type="button" name="submitForm"  value="Send" onclick="dataCheck()" /> <input type="reset" value="Clear"></p>
<a name="sign"></a>
<div align="center"><img src="http://*****.gif" align="middle" height="3" width="100%" /></div>
</form>
<?php

}

else {

$message = addslashes($message);
$name = addslashes($name);
    $query = "INSERT INTO guests SET message='$message', name='$name', date=NOW()";
    $result = mysql_query($query);

    $ref = $_SERVER['HTTP_REFERER'];
    header("Location:$ref");
}

?>
</body>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.