Call PHP Function in jQuery (var)
- by l3gion
Hello,
I'm facing a small problem that I can't solve by myself.
I have this php function:
function intervalo_manha(){
$que="select id_intervalo,data_15
from intervalo_manha
order by id_intervalo";
$re=mysql_query($que);
$object.="<select>";
$object.="<option></option>";
while(list($id_intervalo, $data_15)=mysql_fetch_row($re))
{
$object.= "<option value=\"".$id_intervalo."\">".$data_15."</option>";
}
$object.="</select>";
return $object;
}
This function return a select with information from database.
I also have this js function:
$(document).ready(function() {
var destTable = $("#dataTable");
$("#btnAdd").click(function() {
var newRow = $("<tr style='margin-left:-60px'><td><INPUT type='checkbox' name='chk'/></td><td><INPUT type='text' name='txt[]' id='txt'/></td><td></td></tr>");
$("#dataTable").append(newRow);
newRow.find('input').autocomplete("get_cols_name.php", {
width: 260,
matchContains: true,
selectFirst: false
});
});
});
This one will add a new row to my table, and for each new input will "activate" autocomplete. What I want to do is, instead of this:
var newRow = $("<tr style='margin-left:-60px'><td><INPUT type='checkbox' name='chk'/></td><td><INPUT type='text' name='txt[]' id='txt'/></td><td></td></tr>");
I would like to have something like this:
var newRow = $("<tr style='margin-left:-60px'><td><INPUT type='checkbox' name='chk'/></td><td><INPUT type='text' name='txt[]' id='txt'/></td><td><?php echo intervalo_manha(); ?></td></tr>");
Calling php function directly will return nothing, and I can't do anything. Is there any way to accomplish this?
Thank you