I have a table in my php code. In the second column of the table, normally it displays “—“, and after i click the submit button, it will display the calculating result in the same page.
For example,
<table>
<tr><td>1</td><td>---</td></tr>
<tr><td>2</td><td>---</td></tr>
<tr><td>3</td><td>---</td></tr>
</table>
And in the same page, it should receive the variables
$var1 = $_POST[‘variable1’];
I’m not sure which way to use, ajax or javascript or just css?
Do you have any ideas?
Thanks
You can use Javascript if you want to use the calculation on the client side, PHP if you want it on the server side. From your question I guess you want it on the server side.
Just submit the form to the same page:
action = "your_page.php".Test if the page is submitted via your form, then display the results (a table with the results), after you calculate them, of course. Else display the page like it is now.
With JavaScript you can use DOM to select that exact td where you want your results and display them there, after you calculate them via JavaScript.
A third option.. ajax, has the advantage that can calculate the results in real time (without pressing the submit button).
You must decide what you want before using one of the methods, each one of them has some advantages and some disadvantages.