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


How to write the php code in onchange attribute?

如何在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>