我无法发布由php echo生成的表单,如下所示。 getelementbyid函数似乎不起作用
<?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>";}?>
答案 0 :(得分:0)
试试这个
<a href='#' onclick='document.getElementById('newmsg').submit();' title='Read message' >
改为
<a href='#' onclick='document.getElementById(\"newmsg\").submit();' title='Read message' >
答案 1 :(得分:0)
您可以通过最小化不必要的动态/服务器端生成的html代码来改进您的编码风格。最终,如果你采用这种编码,你会遇到类似的问题 - 只是一个建议。
<?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>";
?>