I was looking for a solution for a long time. I found many of them similar, but not exactly related to my topic.
I know that you have to work with AJAX, but I do not know exactly how this is put together in order to work properly.
My plan is placing a calculator that will do the calculation without refreshing the page. I put some code on jsfiddle. You can see separated php code, which is a separate HTML comment.
The contents are displayed individually, depending on the selected items from the drop down menu.
Each has a different content item that the php code has a fixed value (for example $ilosc1 = 19 \ \ 24 line of HTML)
In javascript I set this to always on the first entry to appear first content (item1 tab). The problem is that when I doing calculations on the page (using the menu - item2), and when I click 'Calculate', the page automatically reloads and the item1 content shows firstly. And to see the result of the calculation of item2 I need re-select the position from the menu list to item2.
Calculator PHP code:
<?php
if ($_GET['calc'] == "yes")
{
$item1 = $_GET['item1'];
$item2 = $_GET['item2'];
$item3 = $_GET['item3'];
$ilosc1 = 19;
$ilosc2 = 21;
$ilosc3 = 25;
$area1 = $item1*$ilosc1;
$area2 = $item2*$ilosc2;
$area3 = $item3*$ilosc3;
}
?>
Simple PHP prints (between h4 tags) in Price Place (with $ on jsfiddle result window):
<?php print $area1+0 ?> //I set '+0' to always shows 0$ in <h4></h4>
I set form's action to:
<?php $_REQUEST['self'] ?>
and method to GET (method="get")
Maybe is there any other way to avoid AJAX or Javascript and make it in pure PHP (the main thing I mean without refreshing page)?