gpt4 book ai didi

javascript - 使用 javascript 形成两个 Action

转载 作者:行者123 更新时间:2023-11-28 07:17:04 25 4
gpt4 key购买 nike

尝试首先使用一个 js 按钮填充字段,然后使用第二个 js 按钮提交收集数据当我单击“填充”按钮时,我可以获取要填充的字段,但是当我尝试提交时,ordertest.php 上没有显示任何值

谢谢

<form action="#" name="data" id="data">
<input type='button' value='Populate' onclick='popContact()' /><BR>
<input type="submit" onclick="document.getElementById('data').action = 'ordertest.php'" value="Payment Submit" /><BR>
Contact Info:<BR>
First Name: <input type='text' readonly="readonly" name='cfname' /><BR>
Last Name: <input type='text' readonly="readonly" name='clname' /><BR>
Email:<input type='text' readonly="readonly" name='cemail' /><BR>
</form>

<script type="text/javascript">
function popContact()
{
var c = window.external.Contact;
data.cfname.value = c.FirstName;
data.clname.value = c.LastName;
data.cemail.value = c.EmailAddr;
}
</script>

---> ordertest.php
<?php
$current_firstname = $_POST["cfname"];
$current_lastname = $_POST["clname"];
$current_email_address = $_POST["cemail"];
echo "current_firstname ".$current_firstname;
echo "<br>";
echo "current_lastname ".$current_lastname;
echo "<br>";
echo "current_email_address ".$current_email_address;
?>

也尝试过

<input type="submit" onclick="this.form.action='ordertest.php'"  value="Payment Submit" />

最佳答案

奥普。

使用此组合有效,$_GET

<input type="submit" onclick="this.form.action='order.php'" method="POST"  value="Payment Submit" />



---> ordertest.php
<?php
$current_firstname = $_GET["cfname"];
$current_lastname = $_GET["clname"];
$current_email_address = $_GET["cemail"];
echo "current_firstname ".$current_firstname;
echo "<br>";
echo "current_lastname ".$current_lastname;
echo "<br>";
echo "current_email_address ".$current_email_address;
?>

关于javascript - 使用 javascript 形成两个 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30743158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com