我有一个由2列组成的表,ContactName和Usertype。我有一个下拉列表,其中包含来自ContactName的数据。当我在下拉列表中选择任何值时,应根据所选内容显示其Usertype。请帮我。到目前为止,我已经做了这么多。当我在下拉列表中选择任何值时,会显示相同的值,但我想要用户类型。
<?php
if(!isset($_SESSION)) {
session_start();
}
$dingo=$_SESSION['dingo'];
$query11="Select ISO3,Notify,Dingoid from rahul_tbl_users where Dingoid=$dingo";
$query123=mysql_query($query11);
$query1234=mysql_fetch_array($query123);
$fetch=mysql_query("SELECT tdd.Dingoid,tc.Dingoid,tc.A_End,tbidd.OpportunityNumber, tbidd.Status,tbidd.Country,tbidd.OpportunityName,tbidd.Allocatedto,tbidd.Email,tbidd.Customer,tbidd.Country,tbidd.ContactName,tc.Usertype,tbidd.G1_OPPID
FROM scott123.rahul_tbl_users tdd inner join scott123.rahul_user_opps tc on
tdd.Dingoid=tc.Dingoid Inner Join scott123.rahul_tbl_opportunities tbidd
on tc.A_End=tbidd.OpportunityNumber
WHERE tc.Dingoid =$dingo");
$fetch_result=mysql_fetch_array($fetch);
?>
<form method="post" action="">
<?php
$SQLString="SELECT distinct(G1_OPPID),ContactName from rahul_tbl_opportunities where G1_OPPID IS NOT NULL and ContactName!='' ";
$result1 = mysql_query($SQLString);
$select_box='<select name="select1" id="select1" onchange="javascript:load_value(this.value);">';
$input="";
while($rows1 = mysql_fetch_array($result1)) {
$select_box .='<option id="user_name" value="'.$rows1["ContactName"].'">'.$rows1['ContactName'].'</option>';
}
$input ='<input type="text" name="test" id="test" value="" />';
echo $select_box."</select>";
echo $input;
?>
<input type="submit" name="submit_name11" value="Add Permission"/>
<input type="submit" name="submit_name12" value="Edit Permission"/>
</form>
答案 0 :(得分:0)
我收集的是您只想让文本框显示当前在选择框中选择的内容吗?
将选择框中的onchange事件更改为:
onchange="transferValue();"
并添加此脚本标记:
<script type="text/javascript">
function transferValue(){
var selectBox = document.getElementById("select1");
var selectedOption = selectBox.options[selectBox.selectedIndex].value;
var textBox = document.getElementById("test");
textBox.value = selectedOption;
}
window.onload = function(){
transferValue();
};
</script>