文档.写和保存到数据库与php


Document.write and Save to db with php

我想知道是否有可能用PHP保存一些数据,从javascript与document.write放置在页面中的表单中获取值,其值已由javascript与document.getElementbyId(id).value设置。

我知道,与.innerHTML()它不工作,因为保存按钮没有得到一个值设置与.innerHTML()方法。

所以我想知道,它会工作,如果我有javascript放置一个输入框与document.write,然后它的值是由另一个js函数设置?

可以,只要您将<input>放置在表单中。

下面是一个简单的例子:

PHP:

<?php
if( !empty( $_POST['hidden_input']))
{
    die( 'Value: ' . $_POST['hidden_input']);
}
HTML:

<form action="test.php" method="POST">
<script type="text/javascript">
    document.write( '<input id="hidden_input" type="hidden" name="hidden_input" value="0" />');
</script>
<input type="submit" name="submit" value="Submit" />
</form>
<script type="text/javascript">
    window.onload = function() {
        document.getElementById('hidden_input').value = 'Changed with JS';
    } 
</script>