【发布时间】:2014-08-09 14:49:45
【问题描述】:
我有一个表单可以转到另一个页面并执行一些数据库操作。
<form id="form1" method="post" action="goes_to_page1.php" onsubmit="return checkformvalidation();">
<input type="text" id="field1" name="field1" onblur="checkvalue(this.value)">
<input type="text" id="field2" name="field2">
<button type="submit" id="butnid" >Go to page 1</button>
<form>
<script>
function checkvalue(val)
{
if(val==10)
{
document.getElementById("butnid").innerHTML = "Go to page 2";
}
<script>
所以我的表单转到 gos_to_page1.php 并执行一些数据库操作。但是我在 field1 的 onblur 属性上调用了一个函数。因此,如果 field1 的值为 10,按钮的标签将更改为转到第 2 页。如果值为 10,我希望我的页面重定向到 gos_to_page2.php 并执行一些其他操作。甚至可以根据按钮的文本来做到这一点吗?
goes_to_page1.php
<?php
$f1=$_POST['field1'];
$f2=$_POST['field2'];
// submit to table1 in database
?>
goes_to_page2.php
<?php
$f1=$_POST['field1'];
$f2=$_POST['field2'];
// do some other operation in database
?>
【问题讨论】:
-
不要基于客户端。将它建立在您进行了一些数据库操作的页面上
-
你能说得更具体点吗? @ejay_francisco
-
而不是调用函数
onblur让您的gos_to_page1.php 检查您的field1 的值。然后在该页面上执行ifelse以重定向,如果值为 10
标签: javascript php html button