8 Replies - 3635 Views - Last Post: 09 September 2012 - 11:11 PM

#1 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

form data lost on history.go(-1)?

Posted 09 September 2012 - 03:50 PM

So I have an agreement form which user must agree before submitting order after form selection.
A link opens up the agreement contents. I add a javascript button on the form:

<button id="goback" onclick="window.history.go(-1);">go back</button>


but the form data will be lost when the button is clicked. Some say to save form data on server (php). Is there a way javascript can save the data on client side?

Is This A Good Question/Topic? 0
  • +

Replies To: form data lost on history.go(-1)?

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: form data lost on history.go(-1)?

Posted 09 September 2012 - 04:25 PM

You could set a cookie on the user's machine, but why not have the agreement just open in its own window so they can read it and then close it and go back to the other window to agree to it? Or you could create a textarea, put the agreement text in that and lock it off from editing.

These three ways all work. :)
Was This Post Helpful? 1
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: form data lost on history.go(-1)?

Posted 09 September 2012 - 04:46 PM

I'd probably just open up the agreement form first, before the user is allowed to proceed to the order form. There's no reason for the user to have to fill out the form, only to find out when submitting it that they have to agree to your terms first.
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: form data lost on history.go(-1)?

Posted 09 September 2012 - 04:47 PM

Atli makes a good point. :)
Was This Post Helpful? 0
  • +
  • -

#5 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: form data lost on history.go(-1)?

Posted 09 September 2012 - 07:07 PM

View PostMartyr2, on 09 September 2012 - 04:25 PM, said:

You could set a cookie on the user's machine, but why not have the agreement just open in its own window so they can read it and then close it and go back to the other window to agree to it? Or you could create a textarea, put the agreement text in that and lock it off from editing.

These three ways all work. :)


I am trying to open a new window:

<a href="http://domain.com/agree.html" onclick="window.open(\"http://domain.com/agree.html\");">agreement</a>


says syntax error? how do I open a separate window?

This post has been edited by g37752: 09 September 2012 - 07:17 PM

Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: form data lost on history.go(-1)?

Posted 09 September 2012 - 07:21 PM

If you specify an URL in the "href" attribute, then clicking the link would redirect you to that URL despite the fact that you are using the onclick handler as well. You need to block the default behaviour of the link; stop it from sending you to the URL.

The simplest way to do that is to put javascript: void(0); as the link href value.
<a href="javascript: void(0);" onclick="...">Agreement</a>


Was This Post Helpful? 1
  • +
  • -

#7 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: form data lost on history.go(-1)?

Posted 09 September 2012 - 08:31 PM

hmm.. neither browser works perfectly.

1, firefox always opens up in a new tab, not a new window, no matter what size I specify?
2, IE always gives me "invalid argument" because my starting URL is utf-8?
Was This Post Helpful? 0
  • +
  • -

#8 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: form data lost on history.go(-1)?

Posted 09 September 2012 - 09:01 PM

it appears that the window name parameter is required for both browser..
Was This Post Helpful? 0
  • +
  • -

#9 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: form data lost on history.go(-1)?

Posted 09 September 2012 - 11:11 PM

As far as my tests have shown, no browser actually requires that. I've observed the following in Chrome, Firefox and IE.
// Opens a new tab
window.open("test.html");

// Opens a 550x400 popup window.
window.open("test.html", "TestWindow", "width=550,height=400");

// No notable difference from the above version.
// (Although I would still set the name, in case you
// want to manipulate the window further later on.)
window.open("test.html", null, "width=550,height=400");



Note, however, that browser specific settings may apply. Some browsers include settings that allow users to force popup windows to open as tabs (Firefox and IE, at least). There is no way for you to bypass such settings. - Some browsers also include popup blockers that may interfere. Again, this is not something you can bypass.

In general, popup windows should be avoided as much as possible. It's a rather annoying way to display info, both for the developer and the user. If you could show your agreement before the form, as I suggested, or by including it in the current page, that would be better.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1