简体   繁体   中英

how to increment value in javascript with the value from the form

<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.

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM