显示和更改HTML输入字段

时间:2016-07-26 14:40:42

标签: javascript html

我有一个PHP文件,其中设置了用户名和年龄。我现在要做的就是获得它们的价值,以便在警报中显示它。我稍后会更改这些值(因此你看到method =“POST”)。现在我只想抓住价值并看看它们是什么。但看起来我错过了什么或做错了什么。最终,我希望能够更改用户名和年龄,并在没有用户交互的情况下提交表单(这是我真正陷入困境的地方)。我很感激任何建议。非常感谢你。

在loaduser.php中,我完成了以下操作:

<input id="username" type="text" name="username" value="<?php echo $username ?>">
<input id="age" type="number" name="age" value="<?php echo $age ?>">

然后在change.html中,我正在执行以下操作:

<body onload="document.forms[0].submit()">
<form action="/loaduser.php" onsubmit="" method="POST">
<a href="javascript: submitform()"></a>
</form>
<script type="text/javascript">
function submitform()
{
  alert(document.getElementById('username').value);
  alert(document.getElementById('age').value);
}
</script>
</body>

我的预感是我可能错误地使用了这条线,但我不确定。

<a href="javascript: submitform()"></a>

1 个答案:

答案 0 :(得分:1)

没有php它看起来像这样。单击提交按钮时,它会将您的数据发布到loaduser.php(提示:在浏览器上使用F12查看网页上的网络流量/错误)。祝你好运

 Limit  (cost=657.35..40441.29 rows=10 width=86) (actual time=24242.233..24242.233 rows=0 loops=1)
         ->  Nested Loop  (cost=657.35..632794743.21 rows=159058 width=86) (actual time=24242.225..24242.225 rows=0 loops=1)
               Join Filter: ((house.adresspointid)::text = (adresspoint.id)::text)
               ->  Index Scan using pk_house on pk_house house  (cost=0.56..17531908.09 rows=6841197 width=123) (actual time=0.074..12008.484 rows=8222065 loops=1)
               ->  Materialize  (cost=656.80..68209.88 rows=5995 width=37) (actual time=0.001..0.001 rows=0 loops=8222065)
                     ->  Bitmap Heap Scan on adresspoint (cost=656.80..68179.90 rows=5995 width=37) (actual time=5.294..5.294 rows=0 loops=1)
                           Recheck Cond: ('0103000020E8640000010'::geometry ~ "position")
                           Filter: ((id_lokalid IS NOT NULL) AND _st_contains('0103000020E864'::geometry, "position"))
                           ->  Bitmap Index Scan on adresspoint_idx_position  (cost=0.00..655.30 rows=17984 width=0) (actual time=5.286..5.286 rows=0 loops=1)
                                 Index Cond: ('0103000020E'::geometry ~ "position")
 Planning time: 17.286 ms
 Execution time: 24242.705 ms