我需要你的帮助在我的网络界面我有一个选择框,返回mysql数据库的数据所以我想当我从我的选择框中选择一些东西我需要它出现在textarea这是我的代码:
<?php require_once('config.php'); ?>
<html>
<head>
<title>Dynamic Dependent Dropdown with jQuery</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#country').change(function(){
var country_id = $('#country').val();
if(country_id != 0)
{
$.ajax({
type:'post',
url:'getvalue.php',
data:{id:country_id},
cache:false,
success: function(returndata){
$('#city').html(returndata);
}
});
}
})
})
</script>
</head>
<body>
<div class="wrapper">
<h1>Dynamic Dependent Dropdown with jQuery</h1>
<p><a href="http://coffeecupweb.com/">http://coffeecupweb.com/</a></p>
<form>
<div class="inputbox">
<select id="country" class="selectbox">
<option value="0">Please Select a country</option>
<?php $sql = mysql_query('SELECT * FROM `countries`'); ?>
<?php while($row = mysql_fetch_array($sql)){ ?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
<?php } ?>
</select>
</div>
<div class="inputbox">
<select id="city" class="selectbox">
<option value="0">Please select a city</option>
<option></option>
</select>
</div>
</form>
</div>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test[]" multiple="multiple">
<option value="and">and</option>
<option value="or">or</option>
<option value="==">==</option>
<option value=">">></option>
<option value="<"><</option>
</select>
<input type="submit" value="Send" />
</form>
<?php
$test=$_POST['test'];
if ($test){
foreach ($test as $t){echo 'You selected ',$t,'<br />';}
}
?>
Text: <textarea name="comment" rows="5" cols="40">
<?php
$comment=$_POST['country'];
if ($test){
foreach ($test as $t){echo 'You selected ',$t,'<br />';}
}
$comment=$_POST['city'];
if ($comment){
foreach ($comment as $t1){echo 'You selected ',$t1,'<br />';}
}
?></textarea> </div>
</body>
</html>
这个代码适用于我选择我所在国家的城市,但它不能在textarea中工作,我希望每一个我从选择框中选择一些东西出现在我的选择框中。提前预订
答案 0 :(得分:1)
使用javascript事件..编写一个函数,该函数将获取选择值并将其附加到文本区域的现有数据。
onselect="saveDataToTextArea();"
<script>
function saveDataToTextArea(){
var selectedValue = $("#idOfSelectField").val();
$("#idOfTextArea").val($("#idOfTextArea").val()+selectedValue );
}
</script>
答案 1 :(得分:0)
您需要向name
元素添加<select>
个属性,以便填写$_POST['country']
和$_POST['city']
。
<select id="country" name="country" class="selectbox">
<select id="city" name="city" class="selectbox">