表格不是由getElementById发布的

I am having trouble posting a form generated by php echo as below. The getelementbyid function does not seem to work

   <?php include 'connect.php' ;
$sql=mysql_query("SELECT mess_id,receiver,subject FROM messages ORDER BY last_update ASC");
while($row = mysql_fetch_array($sql))
                  {
echo "<form  id='newmsg' action='inbox.php' enctype='multipart/form-data' method='post'>
    <li class='message-menu'>
        <span class='message-status'>
            <a href='javascript:void(0)' class='starred' title='Starred'>Starred</a>
            <a href='javascript:void(0)' class='new-message' title='Mark as read'>New</a>
        </span>
        <span class='message-info'>
            <span class='blue'>17:12</span>
            <a href='javascript:void(0)' class='attach' title='Download attachment'>Attachment</a>
        </span>
        <input type='hidden' name='mess1' value='yes' />
        <input type='hidden' name='mess_id' value='" . $row['mess_id'] . "' />
        <a href='#' onclick='document.getElementById('newmsg').submit();' title='Read message' >";
            echo "<strong class='blue'>" . $row['receiver'] . "</strong><br>
            <span class='message-status'></span>
            <span class='message-status'>

        </span>
            <span class='message-info'></span>";
                    echo "<strong >" . $row['subject'] . "</strong>
        </a>
    </li></form>";}?>

Try this

<a href='#' onclick='document.getElementById('newmsg').submit();' title='Read message' >

change into

<a href='#' onclick='document.getElementById(\"newmsg\").submit();' title='Read message' >

You can improve in your coding style by minimizing unnecessary dynamic/server-side-generated html codes. Eventually, you will encounter similar problems if you pursue this kind of coding - just an advice.

<?php

// your mysql query here

echo "<form  id='newmsg' action='inbox.php' enctype='multipart/form-data' method='post'>
    <li class='message-menu'>
        <span class='message-status'>
            <a href='javascript:void(0)' class='starred' title='Starred'>Starred</a>
            <a href='javascript:void(0)' class='new-message' title='Mark as read'>New</a>
        </span>
        <span class='message-info'>
            <span class='blue'>17:12</span>
            <a href='javascript:void(0)' class='attach' title='Download attachment'>Attachment</a>
        </span>
        <input type='hidden' name='mess1' value='yes' />
        <input type='hidden' name='mess_id' value='" . $row['mess_id'] . "' />
        <a href='#' onclick=\"document.getElementById('newmsg').submit();\" title='Read message' >";
            echo "<strong class='blue'>" . $row['receiver'] . "</strong><br>
            <span class='message-status'></span>
            <span class='message-status'>

        </span>
            <span class='message-info'></span>";
                    echo "<strong >" . $row['subject'] . "</strong>
        </a>
    </li></form>";

?>