[英]jquery - How to add image to the Select2 dropdown list with data retreived from MySQL and PHP through AJAX?
[英]Change Textbox from Dropdown List through AJAX, PHP and MYSQL
我有一個表,其中包含2列,即ContactName和Usertype。 我有一個下拉列表,其中包含來自ContactName的數據。 當我在下拉列表中選擇任何值時,應根據所選內容顯示其用戶類型。 請幫我。 到目前為止,我已經做了很多。 當我在下拉列表中選擇任何值時,都會顯示相同的值,但是我需要用戶類型。
<?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>
我收集的是您只希望文本框顯示選擇框中當前選擇的內容嗎?
在選擇框中將您的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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.