Kasun Sampath Kasun Sampath - 1 year ago 53
HTML Question

Incrementing value by 1 each time the form loads/submitted

This is my html code to display a value in a html label

<table >
<tr><td height="40" colspan="2" align=right>
<div class="headbox" >Order No.</div></td>
<td align=left> <div class="headbox" ><label id=no > </label></div> </td>


These are the javascript functions to display the number in the label when form loads

function noDisplay(){
var value =1

document.getElementById('no').innerHTML = value;


window.onload = function(){

Though i want to increase the value of the number by 1 each time the form loads it still remains as 1! how can i rectify this(i.e enter image description hereincrease the value to 2 when the form is submitted or loaded again?)

Answer Source

You can also use localStorage variable to save the value.

    function noDisplay(){

    var count = localStorage.getItem("count")==null?1:localStorage.getItem("count");
    localStorage.setItem("count", count);
    document.getElementById('no').innerHTML = count;

This is to update the label to show how many times form is loaded only. If you need order number, then you need to pass order number from server only.