Please see my code below. The goal is the following. When a user presses the button, the function main.php should be executed. Once it’s finished, the content of DIV opt_container should be filled by running function ganttchart.php. Indeed I don’t know how to:
- execute
ganttchart.phpright aftermain.php. - run
main.phpfromform.
Since I’m newbie in PHP, any suggestions will be very helpful to me.
<div id="fragment-2">
<table width="100%">
<tr>
<td width="100%">
<form name="optform" method="post" action="">
<div class="buttons">
<a href="" class="regular" onclick="click_function();return false;">
<img src="images/opt.png" alt=""/> Run optimizaton
</a>
</div>
</form>
</td>
</tr>
</table>
</div>
<div id="opt_container">
</div>
<script language="javascript">
function click_function() {
$('#opt_container').load('optim/mainOptim.php');
}
</script>
What you want to do cannot be done only in PHP. PHP script is executed at remote server, which means that a request need to be called in order php to return something. User operates on his local (client) machine.
onclick is a handler to execute javascript code, not php. You need to create javascript function, perform ajax request to php code you want to execute and then, the response place in html document. But the response should already be done by what ganttchart.php do.