English 中文(简体)
为什么形式不阻止提交?
原标题:Why is the form not preventing submission?

我有一个基本的形式,即我作为德米来测试 Java的一些功能。 我的目标是点击提交纽特,并在执行 j字功能之前暂停提交,然后提交表格。 我的法典目前如下,但表格的提交并不受阻,隐蔽的实地价值从未确定。 谁能解释为什么发生这种情况?

<>0> 我知道一种履行同样功能的杂货方法。 我特别试图在不使用 j子的情况下解决这一问题。 如果你唯一的回答是“质量更好”,请不重复。

<html>
<head>
<script type="text/javascript">
function test(){
  document.getElementById("hidden").value="hidden";

  var queryString = $( #decisionform ).formSerialize(); 
  alert(queryString);

  document.getElementById("form").submit();
}
</script>
</head>

<body>

<?php
if ($_POST){
  foreach ($_POST as $key=>$value){
    echo "<b>$key</b> $value<br>";
  }
}
?>

<form action="hello.php" method="post" id="form">
<input name="first" type="text" />
<input name="second" type="text" />
<input name="third" type="text" />
<input name="hidden" type="hidden" />
<input name="submit" type="submit" value="Submit" onclick="test();return false;" />
</form>

</body>
</html>
最佳回答

You don t have an element with the id hidden so document.getElementById("hidden").value="hidden"; will throw an error as you can t set properties on undefined. The script will stop running and never reach return false so the form will submit as normal.

问题回答

try <form action="hello.php" method="post" id="form" onsubmit="test(); return false;">

为了防止提交,您实际上需要在<代码>上添加一个<>return false。 甚至形式本身

同时,在隐蔽领域没有id。

<input name="submit" type="submit" value="Submit" onclick="test();return false;" />

在本案中使用一个固定的纽扣吨,因为你履行提交的职责。

<input name="submit" type="button" value="Submit" onclick="test()" />

您从您的投入中删除了<代码>id。 http://www.un.org。

你们可以使用

onclick="return test()"

在职能结束时,公正的回报是不实的。

在你们的投入中添加id=“hidden”,如:

 <input name="hidden" type="hidden" id="hidden" />




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签