我正在尝试在Jquery中创建一个函数,该函数将获取表单SELECT元素的ID,其中应显示动态创建的选项.但是,我必须为其他表单实例重复这项工作.我创建了以下代码,但它没有用.
function getOffice(ID){
$.post('dynamicOffice.php',{operator:$(this).val()},function(output){
$('ID').html(output);
});
$('ID').removeAttr('disabled');
}
Run Code Online (Sandbox Code Playgroud)
<select id="senderOperator" name="senderOperator" tabindex="1" onchange=getOffice(sender)>
<option value=""><--SELECT an Operator --></option>
<?php getOption($operator,Operator) ?>
</select>
<select id="sender" name="sender" tabindex="1" disabled="disabled">
<option value=""><--SELECT the Operator First --></option>
</select>
Run Code Online (Sandbox Code Playgroud)
<?php
include('generateOption.php');
$country=$_POST['operator'];
$officeSql="SELECT * FROM myoffice WHERE Operator='$country'";
getOption($officeSql,Name);
?>
Run Code Online (Sandbox Code Playgroud)
<?php
include("include/dbConnect.php");
function getOption($rsSql,$colName){
$sResult=mysql_query($rsSql) or die("Could Not Fetch Records");
while ($s_Office = mysql_fetch_array($sResult))
{
echo("<option value='".$s_Office["$colName"]."'>".$s_Office["$colName"]."</option>");
}
}
?>
Run Code Online (Sandbox Code Playgroud)