使用PHP将值从一个html页面传递到另一个html页面
可能重复:使用PHP将值从一个html页面传递到另一个html页面,php,javascript,html,Php,Javascript,Html,可能重复: 我知道这很简单,但由于某种原因,我的代码不起作用,我不知道错误在哪里 在第一页中,我有一个表单字段 第1页: <form action="fare.html" method="post"> <fieldset id="main" style="background-color:#CCC"> <table align="center"> <tr> <td colspan="5">
我知道这很简单,但由于某种原因,我的代码不起作用,我不知道错误在哪里 在第一页中,我有一个表单字段 第1页:
<form action="fare.html" method="post">
<fieldset id="main" style="background-color:#CCC">
<table align="center">
<tr>
<td colspan="5">
<fieldset>
<legend style="color:#F00"><b>Departure Address</b></legend>
<input name="address1" id="address1" type="text" size="15" value="City" />
<input name="" type="submit" />
</fieldset>
</td>
</tr>
</table>
</fieldset>
</form>
<form action="fare1.php" method="post">
<fieldset id="main" style="background-color:#CCC">
<table align="center">
<tr>
<td colspan="5">
<fieldset>
<legend style="color:#F00"><b>Departure Address</b></legend>
<input name="address1" id="address1" type="text" size="15" value="City" />
<input name="" type="submit" />
</fieldset>
</td>
</tr>
</table>
</fieldset>
</form>
出发地址
第2页:
<head>
<?PHP
$address1 = $_POST['address1'];
?>
<script type="text/javascript">
$(window).load(function(){
document.getElementById('from').value = $address1;
})
</script>
</head>
<body>
<div class="content">
<h1>Instructions</h1>
<table width="200">
<tr>
<td colspan="2">
<input type="text" name="from" id="from" /></td>
</tr>
</table>
<!-- end .content --></div>
</body>
$(窗口)。加载(函数(){
document.getElementById('from')。值=$address1;
})
说明书
当我单击submit链接时,页面被重定向,但我在新页面的testfield中看不到值
谢谢
document.getElementById('from').value = "<?php echo $address1; ?>";
编辑:我还是不能去
我把密码改成了这个
第1页:
<form action="fare.html" method="post">
<fieldset id="main" style="background-color:#CCC">
<table align="center">
<tr>
<td colspan="5">
<fieldset>
<legend style="color:#F00"><b>Departure Address</b></legend>
<input name="address1" id="address1" type="text" size="15" value="City" />
<input name="" type="submit" />
</fieldset>
</td>
</tr>
</table>
</fieldset>
</form>
<form action="fare1.php" method="post">
<fieldset id="main" style="background-color:#CCC">
<table align="center">
<tr>
<td colspan="5">
<fieldset>
<legend style="color:#F00"><b>Departure Address</b></legend>
<input name="address1" id="address1" type="text" size="15" value="City" />
<input name="" type="submit" />
</fieldset>
</td>
</tr>
</table>
</fieldset>
</form>
出发地址
第2页:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?PHP
$address1 = $_POST['address1'];
?>
<script type="text/javascript">
$(window).load(function(){
document.getElementById('from').value = "<?php echo $address?>";
})
</script>
</head>
<body>
<div class="content">
<h1>Instructions</h1>
<table width="200">
<tr>
<td colspan="2">
<input type="text" name="from" id="from" /></td>
</tr>
</table>
<!-- end .content --></div>
</body>
无标题文件
$(窗口)。加载(函数(){
document.getElementById('from')。value=“”;
})
说明书
我需要将值从一个html页面传递到另一个html页面,但我甚至尝试为第2页创建.php页面,但仍然不起作用
仍在寻找解决方案:(
谢谢!document.getElementById('from')。value=“”;
document.getElementById('from').value = "<?php echo $address1; ?>";
您还必须将表单操作从fare.html
更改为fare.php
,因为您不能在html页面中使用php功能。
<script type="text/javascript">
$(window).load(function(){
document.getElementById('from').value = '<?php echo $address1; ?>';
})
</script>
$(窗口)。加载(函数(){
document.getElementById('from')。值='';
})
您应该在javascript中回显php变量,因为这是两种不同的语言。我建议您应该在fare.html上编写
<?php
if(isset($_POST["address1"])
{
//echo $_POST["address1"];
$address=$_POST["address1"];
}
?>
document.getElementById('from').value = "<?php echo $address?>";
如何在html页面中获取php变量。您需要将表单操作更改为php页面
<form action="fare.php" method="post">
<fieldset id="main" style="background-color:#CCC">
<table align="center">
<tr>
<td colspan="5">
<fieldset>
<legend style="color:#F00"><b>Departure Address</b></legend>
<input name="address1" id="address1" type="text" size="15" value="City" />
<input name="" type="submit" />
</fieldset>
</td>
</tr>
</table>
</fieldset>
</form>
出发地址
fare.php
<head>
<input type="hidden" id='addressval' value='<?=$_POST['address1']?>'>
<script src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$(window).load(function(){
document.getElementById('from').value = document.getElementById('addressval').value;
})
</script>
</head>
<body>
<div class="content">
<h1>Instructions</h1>
<table width="200">
<tr>
<td colspan="2">
<input type="text" name="from" id="from" /></td>
</tr>
</table>
<!-- end .content --></div>
</body>
你回显$address1了吗?你收到了吗value@AMohammed Hussain我检查了我的答案和它的工作情况..你得到了什么错误..我希望你添加了jquery库..告诉我你面临什么错误??