how to execute logical function without clicking button.
For example html form, where visitor can enter two numbers. Then click button - calculate and php script does calculation
Html code something like this
<form method = "POST" action = "'.$_SERVER['PHP_SELF'].'">
<input type="text" name="first_number" size="5">
<input type="text" name="second_number" size="5">
<input type="submit" name="doit" value="calculate">
</form>
then php script to calculate, for example $first_number+$second_number
But how to do calculation automaticaly? without this <input type="submit" name="doit" value="calculate">
Visitor enters numbers and calculation is shown automatically, depending entered numbers...
automatically executes calculation
Moderator: General Moderators
- Peter Anselmo
- Forum Commoner
- Posts: 58
- Joined: Wed Feb 27, 2008 7:22 pm
Re: automatically executes calculation
To be done automatically, you must use Javascript, not PHP. PHP can only be used when the web server is determining what to send to the client. You want this action to be performed client-side, which requires Javascript.
You can do it using the "onchange" handler in the form fields
Example:
You would of course need to define the "AddNumbers()" function to, in fact, add the numbers and display their value somewhere.
You can do it using the "onchange" handler in the form fields
Example:
Code: Select all
<input type="text" name="first_number" onchange="AddNumbers();" />Re: automatically executes calculation
Thanks for answer. If the only way is javascript, it is not so good. because visitor may disabled javascript....Ok. then better php with button