I'm trying to repeat a certain loop again when a button is clicked i tought about using Javascript but i do not know how I would add something to a php variable
Here is my code:
<?php
$productAmount = 0;
for($i = 0;$i <= $productAmount; $i++)
{
?>
<tr>
<td>
<b>Amount:</b><input name='amount' type='text' required>
</td>
<td>
<b>Product:</b><input name='product' type='text' required>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan='2'>
<button type='button' class='add-btn' id='add-btn'>Check</button>
</td>
</tr>
So what i'm trying to do is add 1 to $productAmount when the button is clicked. But in real time so you immediatly see a result. I do not necessarily need specific code(it is appreciated tough) but a little nudge to the right direction is already a huge help.
</div>
Use AJAX. Here's the link to get started: Ajax Tutorial
Php is a server side language. Your DOM (what the user can see) is client side code. So you can't use it in realtime without javascript, because when you see the website, the php code was already translated to html.
You should use js to increment, and send the value via php.
Anyway, if you want to manipulate your dom, javascript is the easiest way to do so.
Then you wish to add clones of the element: w3schools.com/jquery/html_clone.asp – Dainis Abols