使用javascript后的表单提交

使用javascript后的表单提交,javascript,php,Javascript,Php,我有两个php页面。第一页如下: <?php // --- please consider that my form is inside a while statement... <form action='deletepost.php' method='post' > <input type='hidden' name='var' value='$comment_id;'> <input type='submit' value='delete'

我有两个php页面。第一页如下:

<?php

// --- please consider that my form is inside a while statement...


<form action='deletepost.php' method='post' >
  <input type='hidden' name='var' value='$comment_id;'>
  <input type='submit' value='delete' >
</form>

?>
<?php

    $comment = mysql_real_escape_string($_POST['var']);
    echo" $comment ";

    // --- then starts successfully the delete process I have created...

?>

页面deletepost.php如下所示:

<?php

// --- please consider that my form is inside a while statement...


<form action='deletepost.php' method='post' >
  <input type='hidden' name='var' value='$comment_id;'>
  <input type='submit' value='delete' >
</form>

?>
<?php

    $comment = mysql_real_escape_string($_POST['var']);
    echo" $comment ";

    // --- then starts successfully the delete process I have created...

?>

因此,第一个页面包含一个表单按钮delete,当我按下它时,它会传递我想要成功的page deletepost.php的值(我使用echo查看它,正如您所看到的)。 我已经决定在第一页的表单中使用javascript lightbox。我已将代码更改为:

<?php

<a href = javascript:void(0) onclick = document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'><h2><font color=green size=3>Delete All</font></h2></a>
<div id=light class=white_content>


<form action='deletepost.php' method='post' >
  <input type='hidden' name='var' value='$comment_id'>
  <input type='submit' value='delete' onClick=submit(); >
</form>


<a href=javascript:void(0) onclick=document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'><button style='margin-left:250px; width:95px;'>Cancel</button></a>
</div>
<div id=fade class=black_overlay></div>  

我认为提交输入不需要
onClick
属性。特别是如果您在JS中的任何地方都没有定义
submit
方法。设置该属性足以停止表单的默认提交行为,并将停止php的运行。

我认为在提交按钮上使用javascript没有任何意义。您可以在
上执行此操作,并且应参考表单名称

<form name='form1' action='deletepost.php' method='post'>

...


<button onclick='document.form1.submit()'>delete</button>

以下是我的测试:

test1.php:

<?php $comment_id = 1 ?>
<?php while($comment_id < 10): ?>
    <a href="javascript:void(0)" onclick="document.getElementById('light<?=$comment_id;?>').style.display='block';document.getElementById('fade<?=$comment_id;?>').style.display='block'"><h2><font color=green size=3>Delete All</font></h2></a>
    <div id="light<?=$comment_id;?>" class="white_content" style="display: none">


    <form action="test2.php" method="post" name="form1">
      <input type="hidden" name="var" value="<?=$comment_id;?>" />
      <button onClick="document.form1.submit();">Delete</button>
    </form>


    <a href="javascript:void(0)" onclick="document.getElementById('light<?=$comment_id;?>').style.display='none';document.getElementById('fade<?=$comment_id;?>').style.display='none'"><button style="margin-left:250px; width:95px;">Cancel</button></a>
    </div>
    <div id=fade class=black_overlay></div>
<?php $comment_id++; ?>
<?php endwhile;?>
网页中的输出为:

array (size=1)
  'var' => string '5' (length=1)

从此行中删除onclick事件我做了什么仍然没有关闭下一行中的第一个,并按如下方式使用问题来自javascript lightbox的href,它可能不允许将变量传递到下一页它在表单外部,我只是在使用一个简单的javascript灯箱,怎么可能不允许我将var传递到下一页?我想将$comment\u id传递到下一页,当使用href javascript作为灯箱时,它不会传递它$comment\u id来自哪里?它不只是
$comment
?它来自我的代码,并通过name='var'value='$comment\u id'传递到表单亲爱的朋友谢谢你的帮助…感谢你!