0

i have a form that is created from a textfile. I fill the form with values and then on the next step i just show the values with text. But if any of the values is wrong and i want to change it i would like to be able to go back and change them. But as it is now i can't because then i need to do all the steps again and generate the form again. Is there a way to just go back to the previous page?

now i use

 $(document).on("click", "#btnBackO", function () {
    window.location = "/Home/RiskScore";
});

but this does obviously not work. This code just sends me back to nothing because the form is not generated before it tries to go to the page. Is there a way to go back to a cached page of something?

Daniel Gustafsson
  • 1,725
  • 7
  • 37
  • 78

2 Answers2

0

If you want to go back to previous page :

history.go(-1)


history.back() or history.back(-1) 

should work as well

Thomas
  • 16
  • 2
0

I am pretty sure you would be required to be using some kind of server side language or javascript for this. Reason being is because the only way to "save state" is by passing the values back and forth. So when you hit back it's not like you are just going back to your last state, your essentially reloading the page.

Your code:

$(document).on("click", "#btnBackO", function () {
    window.location = "/Home/RiskScore";
});

would change to something like:

$(document).on("click", "#btnBackO", function () {
    window.location = "/Home/RiskScore?field1=value1&field2=value2"; //etc.. etc..
});

your page that holds the orginal form would have to be at bare minimum an HTML file that can support javascript tags. Preferable doing something server side via PHP:

VERY SIMPLIFIED EXAMPLE: (things like error catching, and escaping special characters are not addressed here)

<?php
    $field1 = $_GET['field1'];
?>
<input type='text' value='<?php echo $field1; ?>' />

Any web language will be capable to accomplish this.

Sources:

How to get the query string by javascript?

http://php.net/manual/en/reserved.variables.get.php

Community
  • 1
  • 1
drankupon
  • 83
  • 6