I am trying to modify a module TPL file and face some difficulties.
I have a dropdown list and want to run an SQL query when the user selects an item from the list. So far I have tried to run a PHP file through Ajax in order to run the query but without any success. I have seen various examples but can't understand how it should be done. Nevertheless here is what I have done so far.
This is the code I use on the TPL file:
<select id="statusSelect" onChange="updateStatus({$order.id_order|escape:'html':'UTF-8'})">
<option value="1"> test1 </option>
<option value="2"> test2 </option>
<option value="3"> test3 </option>
</select>
This is the JS function I use to call the PHP file, through Ajax:
<script type="text/javascript">
function updateStatus(order_id_sent)
{
//TEST
//alert(document.getElementsByTagName("option")[selectedIndex].value + " " + order_id_sent);
$.ajax({
url: 'setStatus.php',
type: 'get',
data: 'ajax=true',
success: function()
{
alert("It worked");
}
});
}
</script>
And here is my setStatus.php file which I want to call:
<?php
include_once('../../../../../config/config.inc.php');
include_once('../../../../../init.php');
public function doStuff()
{
echo "alert('test');";
return 1;
}
if ($_GET['ajax'])
{
echo function doStuff();
}
?>