0

我有一个通过 javascript 提交表单的 html 页面。在提交表单之前,我更改了隐藏标签的值,然后尝试进入 php,但它不起作用。它显示为空白。

这是javascript

function remove(){



remove.value = 'true';


  document.newrow.submit() ;


}

remove 的值设置成功,但是当我提交表单时,我得到一个空白值。

这是检索值的 php 代码。

$test = $_POST['remove'];


echo $test;

知道为什么该值为空白吗?

谢谢

<form name = 'newrow' action = 'update.php' method = 'post'>


<input type='hidden' name='remove' id = 'remove' /><a href='javascript:remove()'><img src = 'images/delete.png' / ></a>
4

2 回答 2

2
remove.value = 'true';

Is too ambigous. Try using document.getElementById('remove').value, assuming that the element has remove as its ID.

于 2012-04-09T04:30:27.203 回答
0

You should do like this

<input type='hidden' name='random' id='random' />
<input type='submit' name='enter' value="Enter" onclick="remove" />

function remove() { document.getElementById("random").value='true'; }

//PHP part

if(isset($_POST['enter']))
{
   $ramdom=$_POST['random'];
}

The error probably is that you are submitting it twice

--Update for anchor tag

Here is what you're missing:

A link does not submit the form with input data, it just changes the url.
Submit the form.
Override the default <a> behavior (for example, using return false).

function random()  
{  
    document.getElementById("random").value = 'true';  
    document.getElementById("thisForm").submit();
    return false;
}  

You can call it using:

<a href="" name="enter" onclick="return random();">Enter </a>
于 2012-04-09T04:30:30.070 回答