1
<html>
<script>
    function remain()
    {
        var k=0;
        var rem=<?php echo $count; ?>;
        var cap=document.getElementById("cap").value;
        var k=k+cap;
        var diff=rem-cap;

        document.getElementById("demo").innerHTML = diff;

    }
</script>
</html>

<html>
<form method="post" action="list.php" target="_blank">
    Enter the capacity:
    <input type="number" name="cap" id="cap"  min=1 max=36 onchange="remain()">
    <input type="submit" id="submit" value="get seating">
</form>
</html>

My question is: in the HTML form I will enter the capacity. When I entered the capacity it will be directed to javascript and remaining strength must be show by subtracting the capacity from the total count (ex: i entered the capacity as 36 and let the count be 100).

Now the cap 36 is less from 100 and remaining 64 will be shown. But when again I entered the cap 36 it should be less from remaining 64. But this was not happening.

Randy
  • 9,419
  • 5
  • 39
  • 56
  • 2
    After calculation of `diff` you may set value of `diff` to the input you got value from: `document.getElementById("cap").value = diff;` – zmii Aug 17 '16 at 11:56
  • As a side note, notice that after submitting your form, you might lose your calculation data unless you use some state persistence mechanism (cookies, server side session etc.) – Yair Nevet Aug 17 '16 at 12:09
  • Why are there two `html` tags for what appears to be one document? That is not valid HTML. – Jason Cust Aug 17 '16 at 12:56

1 Answers1

2

Something like this?? Click the geat seating button after mentioning the capacity.

var rem = 100

function remain() {
  var k = 0;
  var cap = document.getElementById("cap").value;
  var k = k + cap;
  rem = rem - cap;

  document.getElementById("demo").innerHTML = rem;
}
<form method="post" action="list.php" target="_blank">
  Enter the capacity:
  <input type="number" name="cap" id="cap" min=1 max=36>
  <input onclick="remain()" type="submit" id="submit" value="get seating">
</form>
<div id="demo"></div>
Pugazh
  • 9,453
  • 5
  • 33
  • 54