gpt4 book ai didi

javascript - 根据链接到数据库的组合框在标签中显示值

转载 作者:行者123 更新时间:2023-12-03 02:43:00 25 4
gpt4 key购买 nike

这是我尝试将值传递到基于组合框的标签中。假设我从组合框中选择 A,如果我选择 B,标签必须更改为 1,则标签更改为 2。

这是我的尝试:

kota.php:

$conn=mysql_connect('localhost','root','root');
$sel = mysql_select_db('test',$conn);
$alamat=$_POST['alamat'];
$query=mysql_query('select * from alamat where jalan="'.$alamat.'"');
while ($data=mysql_fetch_array($query)){
echo '<label value= "' .$data[2].'"> <b> ' .$data[2].' </b> </label>;
}

?>
<小时/>

com_txt.php

<!DOCTYPE html>
<html>
<title>Test Calculator</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css.css">
<link type="text/css" rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Oswald">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open Sans">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="jquery.min.js"></script>
<body>
<label> Jalan: </label>
<select name="alamat" id="alamat" onchange=kota(this.value)";>
<option value=""> --Items -- </option>
<?php $j1=mysql_query($con,'select * from alamat order by id ASC');
while ($jalan=mysqli_fetch_row ($j1)){
echo '<option value="'.$jalan[1].'</option>';
}
?>
</select>
</br>
<label> </br></br> kota:</label> <label name="kota" id="kota"> <b> label</b><label>
</body>
</html>

最佳答案

javascript 在这里发生

您想要将标签值更改为所选选项的索引

function myfun(select) {

document.getElementById('some').innerText = select.selectedIndex;
}
<select onchange="myfun(this)" id=s>
<option value=" ">0</option>
<option value="3">2</option>
<option value="4">3</option>
</select>
<label id=some></label>

关于javascript - 根据链接到数据库的组合框在标签中显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48238548/

25 4 0