-2

Regarding below:

<html>
<head>
</head>
<body onload="document.naughtyWidgets.reset();">
<form name="naughtyWidgets">
… widgets…
</form>
</body>
</html>

The form resets just fine when the page is refreshed. However, if the form is say under page 'X', and one clicks a couple of radio buttons on the form, navigates to page 'Y', and returns to page 'X', the radio buttons are still clicked. Is there any way to reset these buttons to default when revisiting the form?

Thanks

Sparky
  • 98,165
  • 25
  • 199
  • 285
  • 2
    This typically happens when the user clicks the browser's "back" button. In that case, there really isn't a full page load; it's coming from the cache. Your best bet would be to do a form reset whenever you leave the page. – Sparky Jun 07 '14 at 16:49
  • @Sparky Thanks! Would
    suffice?
    – user3677306 Jun 07 '14 at 17:05
  • I have no idea what the `onsubmit` event has to do with leaving your page in this case. You've shown very little here. – Sparky Jun 07 '14 at 17:06
  • @Sparky Could you please inform me which event has to do with leaving the page? – user3677306 Jun 07 '14 at 17:10
  • As per comments on my answer below, OP is not really programming the page, but inserting HTML content into a box within the [Wix Sitebuilder CMS](http://www.wix.com). Voting to close with "not enough information", as well as a few other legitimate reasons... "too broad", "unclear", "not about programming", and maybe a duplicate. – Sparky Jun 07 '14 at 19:43
  • It's about programming alright, otherwise one wouldn't be using javascript. 'Reset radio buttons on form revisit' doesn't seem too broad to me. And clarity...is a very subjective topic. Take care. – user3677306 Jun 08 '14 at 19:53
  • Yet you clearly have **not provided enough information** and have no access to control the page itself, so good luck with that. You'd think the Wix Site builder would have been something to mention in the OP. – Sparky Jun 08 '14 at 20:20

1 Answers1

0

This typically happens when the user clicks the browser's "back" button. In that case, there really isn't a full page load; it's coming from the cache.

Use the onbeforeunload event to trigger a form reset just before leaving the page.

window.onbeforeunload

From here: Best way to detect when a user leaves a web page?


EDIT:

Quote OP's Comment:

"maybe it helps knowing that the website is made using Wix, and the html part is simply an additional box on a page, in which i can add code."

That's a huge detail you should not have left out of your OP. If you're just sticking content into a content box within a CMS, then this issue is likely impossible to fix without control over the entire page.

Community
  • 1
  • 1
Sparky
  • 98,165
  • 25
  • 199
  • 285
  • HA! I was on this page a couple of minutes ago. However the unbeforeunload doesn't seem to work. – user3677306 Jun 07 '14 at 17:11
  • @user3677306, the [demo here](http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm) is working fine for me. – Sparky Jun 07 '14 at 17:15
  • It works when a link on the page is clicked, or when you refresh the page. However, the form is placed under a tab called 'Find'. If I return to 'Home', and come back on 'Find', the form is still as it was, with the radio buttons clicked. – user3677306 Jun 07 '14 at 17:35
  • @user3677306, If you're using some kind of dynamic tab/panel system, then you're not really leaving the page then, are you? If you're not really leaving the page, then of course any `unload` event is never going to work. I can't help you further with what little you've shown in the question. See: http://stackoverflow.com/help/mcve – Sparky Jun 07 '14 at 18:16
  • maybe it helps knowing that the website is made using Wix, and the html part is simply an additional box on a page, in which i can add code. – user3677306 Jun 07 '14 at 18:40
  • @user3677306, if you're just sticking content into a content box within a CMS, then this issue is likely impossible to fix without control over the entire page. It's not our job to investigate what the Wix Sitebuilder template is doing. StackOverflow is geared for _"professional and enthusiast"_ programmers, not CMS users, so it's up to you to know [how to construct a proper demo that reproduces your issue](http://stackoverflow.com/help/mcve). Good luck. – Sparky Jun 07 '14 at 19:45