在 onChange 事件中,我想从数据库而不是静态获取国家/地区,我-6ren">
gpt4 book ai didi

javascript - 如何在onchange属性中编写php代码?

转载 作者:行者123 更新时间:2023-11-28 08:41:58 26 4
gpt4 key购买 nike

如何在onchange事件中编写php代码。

代码:

<select id="country" name="country" onChange=" if(this.value=='other'){ showHint(this.value); this.form['other'].style.visibility='visible'; }else{  showHint(this.value);this.form['other'].style.visibility='hidden';};" class="DropDown" >

<option value="0">Select Country</option>

<?php while($sel_rows=mysql_fetch_array($sel_exe)) { ?>

<option value="<?php echo $sel_rows['CountryId']; ?>"><?php echo $sel_rows['CountryName']; ?></option>

<?php } ?>

</select>

在 onChange 事件中,我想从数据库而不是静态获取国家/地区,我该怎么做?

喜欢。

if(this.value=='fetch from the database instead of other')

最佳答案

您需要使用不同的函数从数据库加载数据,例如

onChange="load_data()"

在此 java 脚本函数内,您可以运行 ajax 请求并加载数据库表单中的数据

   <script>
function load_data()
{
if(this.value=='other'){
showHint(this.value);
this.form['other'].style.visibility='visible';

//Jquery ajax request
$.ajax({
//your database call-up script
url: "test.php",
context: document.body,
success: function(data){
this.value==data;
}
});

}else{
showHint(this.value);
this.form['other'].style.visibility='hidden'

}
}

</script>

关于javascript - 如何在onchange属性中编写php代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20367970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com