[Solved] Use JSON object to store the form data that refreshes again and again [closed]


If you are not using postbacks to submit the (non final) value, then simply push the current value of the input into a JavaScript array.

Then when you do the final submit, you will be able to access all of the previous values of the input from the array.

            //Store the values in here     
            var inputValues = [];
             
            //Click event of non-final submit button
            $(yourButton).on("click", function(e){
                e.preventDefault();
                var submit = confirm("Do you want to submit?");
                if(submit){
                  //submit the values to the database
                }
                else{
                   //Add the current values to the array, this could be as many as you like
                  inputValues.push({
                    input1:$(yourInput).val(),
                    input2:$(yourInput2).val(),
                    input3:$(yourInput3).val(),
                  });

                  //Optional -- Clear the inputs, again as many as you like
                  $(yourInput).val('');      
                  $(yourInput2).val('');   
                  $(yourInput3).val('');   
                }

            })

8

solved Use JSON object to store the form data that refreshes again and again [closed]