Forums

counting with input numbers

xanuex 16 May, 2009
Hi,

I couldn't find anything like this on the forum so here is my question:

Is it possible to count with the numbers filled in by a user?

For example, a user wants to order a couple of things which have a standard price, can I multiply the number that was filled in by the user with the price and show him/her how much he needs to pay?

I was trying to add the following to the onSubmit field, but this doesn't seem to be the solution🙂
You'll have to pay <?php echo "{tickets}"*10;?> euro.

Thanks in advance.
M.
xanuex 16 May, 2009
Created my own answer, sorry to wake you guys up 🤣

<?php echo $_POST['tickets']*10;?>
GreyHead 17 May, 2009
Hi xanuex,

That will work OK; slightly better is
<?php
$number = JRequest::getInt('tickets', ', 'post');
echo $number * 10;
?>
As this checks that the value entered is an integer.

But probably the best solution to this is to calculate the value in the browser using JavaScript to that you show it to the user before they submit.

Bob
This topic is locked and no more replies can be posted.