保存列表框值 [英] Saving A Listbox Value
本文介绍了保存列表框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网页上有三个列表框。我想保存第一个列表框中的值,以便我可以填充第二个列表框。由于重复的问题,我不能把第一个链接到第二个。它有多对多的关系。我如何临时保存值,以便我可以使用它来填充第二个列表框。谢谢。
I have three listboxes on a webpage. I would like to save the value from the first listbox so that I can populate the second. I can''t chain the first to the second because of the problem of duplicates. Its a many to many relationship. How would I save the value temporarly so that I can use it to populate the second listbox. Thank you.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 0);
include("conndb.php");
function createoptions($table , $id , $field , $condition_field , $value)
{
$sql = sprintf("select * from $table WHERE $condition_field=%id ORDER BY $field" , $value);
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) > 0) {
while ($a = mysql_fetch_assoc($res))
$out[] = "{optionValue: {$a[$id]}, optionDisplay: '$a[$field]'}";
return "[" . implode("," , $out) . "]";
} else
return "[{optionValue: -1 , optionDisplay: 'No result'}]";
}
if (isset($_GET['make'])) {
echo createoptions("model" , "model_id" , "model" , "make_id" , $_GET['make']);
}
die();
这是另一页。 ..
This is the other page...
<?Php
include("conndb.php");
function createoptions($table , $id , $field)
{
$sql = "select * from $table ORDER BY $field";
$res = mysql_query($sql) or die(mysql_error());
while ($a = mysql_fetch_assoc($res))
echo "<option value=\"{$a[$id]}\">$a[$field]</option>";
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Select test</title>
<script type="text/javascript" src="jquery-1.2.3.js"></script>
<script type="text/javascript" charset="utf-8">
$(function(){
$("select#make").change(function(){
$.getJSON("select.php",{make: $(this).val(), ajax: 'true'}, function(j){
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
}
$("select#model").html(options);
})
})
})
</script>
</head>
<select id="make">
<option value="-1">--Select--</option>
<?php
createoptions("make", "make_id", "make");
?>
</select>
<select id="model">
</select>
</body>
</html>
我正在使用jquery-1.2.3.js
And I am using jquery-1.2.3.js
推荐答案
tabl e,
table ,
id ,
id ,
字段,
field ,
这篇关于保存列表框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文