日期:2014-05-17  浏览次数:20609 次

一个简单的表单提交,然后返回提交页面,需要相应数据
test3.php:


<html>
<head>
<script type="text/javascript">
function clicksearch()
{
var brand = document.getElementById("brand").value;
var model = document.getElementById("model").value;
var years = document.getElementById("years").value;
var querybuilder = document.getElementById("querybuilder");

querybuilder.value = brand+' '+model+' '+years;

document.getElementById("form1").submit();
}
</script>
</head>

<body>
<form action="test4.php" method="get" id="form1">
<select name="brand" id="brand">
<option></option>
<option value="AAA">AAA</option>
<option value="BBB">BBB</option>
<option value="CCC">CCC</option>
</select>

<select name="model" id="model">
<option></option>
<option value="DDD">DDD</option>
<option value="EEE">EEE</option>
<option value="FFF">FFF</option>
</select>

<select name="years" id="years">
<option></option>
<option value="GGG">GGG</option>
<option value="HHH">HHH</option>
<option value="III">III</option>
</select>
<!-- <input type="submit" value="Enter" name="enter"> onclick="clicksearch();"-->
<a href="javascript:clicksearch();">Enter</a>
</form>
<br>
<form action="test5.php" method="post">
<input type="text" name="querybuilder" id="querybuilder" value="search here...">
<input type="submit" name="search" value="查询">
</form>
</body>
</html>




test4.php:

<?php
$brand = $_REQUEST["brand"];
$model = $_GET["model"];
$years = $_GET["years"];
$a = array($brand,$model,$years);
?>

现在想取得$a,并且在表单提交页面的
<input type="text" name="querybuilder" id="querybuilder" value="search here...">
改变value值,值为$a数组里面的元素。

谢谢了


------解决方案--------------------
定义一个全局变量,在test3.php提交时赋值,返回时,调用就OK了。
PHP code

//全局变量页面
//ini.php
$ini = array();

------解决方案--------------------
数组不是同样的道理? 关键你要怎么显示?
------解决方案--------------------
test4.php:

<?php
$brand = $_REQUEST["brand"];
$model = $_GET["model"];
$years = $_GET["years"];
$a = array($brand,$model,$years);

include 'test3.php';
?>


test3.php
...
<input type="text" name="querybuilder" id="querybuilder" value="<?php echo join(',', $a) ?>">
...