Is there a way where there is a number on the screen, for example 100, and a form where you can insert a number in the form and that number will be deducted from the one displayed.
So if i inserted 5, the number will become 100 and can there also be a reset button

as much as possible i want to do this with php and html only

Recommended Answers

All 3 Replies

Member Avatar for diafol

How is this connected to your title? Are you asking if it.s possible to deduct a number in a form from another number. Yes. Shouldn.t your example then display 95? This can be done easily in js. Painful in php as a round trip to server and page reload required each time.

Painful in php as a round trip to server and page reload required each time.

This can be done easily in js.

I suggest do this as @diafol said

If you want to do this with only PHP and HTML, you have to submit your page on each actions, ie when you submit your number and reset your value. That takes to load page again and again. Try the below example:

<html>
<body>
<?php
$result = 100;
if(isset($_POST['hdnValue']) && isset($_POST['txtValue'])){
    $result = $_POST['hdnValue'] - $_POST['txtValue'];
}
?>
<h1><?php  echo $result; ?></h1>
<form action="#" method="post">
<input type="hidden" value="<?php  echo $result; ?>" name="hdnValue" />
<input type="text" name="txtValue" />
<input type="submit" value="Enter" />
</form>
<form action="" method="post" >
<input type="submit" value="Reset" />
</form>

</body>
</html>

lol that code above from @Bachu IS the answer to the question that was asked, but as @diafol pointed out, the question is in no way connected to the title, haha

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.