javascript - 是否可以根据按钮名称将表单的值从按钮提交到两个页面?

标签 javascript php html button

我有一个表单,它会转到另一个页面并执行一些数据库操作。

 <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
?>

最佳答案

这是第1页..

$GLOBALS['f1']=$_POST['f1']; $_GLOBALS['f2']=$_POST['f2']; 如果($f1==10) {

标题(“位置:goes_to_page2.php”); 导出; }

第 2 页

$f1= $GLOBALS['f1']; $f2=$GLOBALS['f2'];

现在form的值在page2的变量中..

这是正确的答案吗?

关于javascript - 是否可以根据按钮名称将表单的值从按钮提交到两个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24300270/

相关文章:

php - 如何将 PayPal 交易详细信息放入 Codeigniter 中的数据库

python - 用python抓取点击时出现的表格

javascript - 查找 Javascript 对象中属性的交集

javascript - 通过在 JavaScript 中单击更改按钮文本

javascript - 内嵌框架 : Remove iframe scroll and use window scroll to view the content of the iframe

javascript - ColdFusion CFC CORS 和 AJAX 帖子

php - 在 PHP 不工作的情况下向浏览器显示 PDF

php - Symfony 5 如何存储氩气的盐?

html - 挣扎于嵌套的 flexbox 网格

html - 带有文本的 Div 移动其他元素