I'm trying to make a function in Jquery that will take the ID of form SELECT element's ID where a dynamically created option should be displayed. But, i have to repeat this work for other form instances as well. i have created the following code, but it did not work.
function getOffice(ID){
$.post('dynamicOffice.php',{operator:$(this).val()},function(output){
$('ID').html(output);
});
$('ID').removeAttr('disabled');
}
<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>
<?php
include('generateOption.php');
$country=$_POST['operator'];
$officeSql="SELECT * FROM myoffice WHERE Operator='$country'";
getOption($officeSql,Name);
?>
<?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>");
}
}
?>
Remove the quotes from around the parameter, and concatenate a #
to the beginning of it.
$('#' + ID).html(output);
$('#' + ID).removeAttr('disabled');
Also, this
will likely reference the window
instead of whatever element you expect, so the following won't work:
{operator:$(this).val()}
If it should reference the select
element, then add this
as a second argument:
onchange=getOffice(sender,this)
...and reference it with a parameter:
function getOffice(ID, el){
$.post('dynamicOffice.php',{operator:$(el).val()},function(output){
$('#' + ID).html(output);
});
$('#' + ID).removeAttr('disabled');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With