I am trying to make a function in jQuery that will take the form identifier of the ID of the SELECT element where the dynamically created option will be displayed. But I have to repeat this work for other instances of the form. I created the following code, but it does not work.
JQuery Script
function getOffice(ID){
$.post('dynamicOffice.php',{operator:$(this).val()},function(output){
$('ID').html(output);
});
$('ID').removeAttr('disabled');
}
The main HTML file
<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>
dynamicOffice.php
<?php
include('generateOption.php');
$country=$_POST['operator'];
$officeSql="SELECT * FROM myoffice WHERE Operator='$country'";
getOption($officeSql,Name);
?>
generateFormElement.php
<?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>");
}
}
?>
source
share