这是我的下拉框代码:-
<select name="cat" id="cat" onchange="get_data(this.value)" required>
<option disabled selected value> -- select an option -- </option>
<option value="team1">team1</option>
<option value="team2">team2</option>
<option value="IT">IT</option>
<option value="Manager">Manager</option>
</select>
我的文本框代码如下:-
<input placeholder="Phone Number" name="phoneNumber" type="text" required>
JavaScript代码:-
function get_data(value){
$.ajax({
url: "ajaxdropdown.php",
type: "POST",
dataType: "HTML",
async: false,
data: {value: value}
});
}
</script>
ajaxdropdown.php
<?php
include('session.php');
$cat = (filter_input(INPUT_POST, 'cat'));
$sql = mysql_query("select Mobile from user_content where Category='" . $cat . "'") or die(mysql_error());
$value_frank = mysql_fetch_row($sql);
$val_fra = $value_frank;
echo $val_fra;// here no need to use sessions at all.
?>
我的示例数据库表:-
-------------------------
| ID | Category | Mobile |
-------------------------
| 001 | team1 | 962222 |
| 002 | team2 | 962562 |
| 003 | team2 | 962334 |
-------------------------
所以我想根据我的下拉选择来更改文本框的值。
例如,当我选择下拉值“ team2”时,它将检查数据库并在我的文本框中显示匹配的Moblie字段记录,并用逗号一一隔开。
下拉值选择:team2 文字框值:962562,962334
任何帮助都将不胜感激。