Page 1 of 1
Php Number
Posted: Thu Dec 08, 2016 1:29 am
by php75
Hi,
By using PHP i want to display numbers automatically once i enter the numbers in textbox/number/time without click submit button.How can i do it?

Re: Php Number
Posted: Thu Dec 08, 2016 5:51 am
by requinix
Be more specific. What numbers? What textbox? What button? Why do you need PHP for this?
Re: Php Number
Posted: Thu Dec 08, 2016 8:41 pm
by Christopher
Yes, we need more information. In general with web apps, if something happens automatically based on another event then Javascript is involved.
Re: Php Number
Posted: Thu Dec 08, 2016 10:35 pm
by php75
thank you for your reply..Just i want to learn about it...For example By using Arithmetic operators If i type some numbers with or without decimal values in html text box then without clicking automatically displays some values in table content.
This is my doubt...If possible give me a source code with explanation....
Re: Php Number
Posted: Thu Dec 08, 2016 11:24 pm
by requinix
The principle of "don't reload the page but have PHP do something" is called AJAX. Javascript makes a request to your server just like any regular URL, except it happens behind the scenes without the browser needing to change the current page.
However you might not need it at all. Like if you want to do addition, you can do that entirely in Javascript. No PHP needed at all.
Code: Select all
<div class="calculator">
<input type="number" name="a">
<select name="op">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input type="number" name="b">
=
<input type="number" name="c" readonly>
</div>
<script type="text/javascript">
// using jquery
$(function() {
$(".calculator").each(function() {
var $a = $("[name='a']", this);
var $op = $("[name='op']", this);
var $b = $("[name='b']", this);
var $c = $("[name='c']", this);
var recalculate = function() {
// eval is evil... but easy. and this is only a demonstration anyways
$c.val(eval(parseInt($a.val(), 10) + $op.val() + parseInt($b.val(), 10)));
};
$a.keydown(recalculate);
$op.change(recalculate);
$b.keydown(recalculate);
});
});
</script>
Untested but should be close.