How do you call a PHP function that is in a different file from a JavaScript function?
I have a JavaScript function that recieves a variable from an onclick function. The variable is an id that I will use to retrieve data from a MySQL database. The variable is then passed on to a PHP function that will access the database to get the data and return back to my JavaScript function for display, but it does not seem to be working. How can I get it to work? I am using CodeIgniter PHP.
Here is the code.
The JavaScript code is in a different file called divUpdate.php
.
<script type="text/javascript">
function changeDiv(venueID){
//retrieveData(venueID) is a PHP function from venue_model.php
var dest = retrieveData(venueID);
document.getElementById('venue_description').innerHTML=dest;
}
</script>
---Where the onclick function calls the JavaScript code above. ----
<li><a href="#self" class="menulink" class=&{ns4class};
onClick="changeDiv(\''.
$venue_details->VenueID.
'\')">;
--- Function retrieveData is called from the JavaScript code above. This is in the model (CodeIgniter). --
function retrieveData($venueID){
$query = $this->db->query("SELECT * FROM venue WHERE VenueID = '$venueID' ");
echo $query;
}