简体   繁体   中英

Back button Javascript issue

So I have a page where I am making selections using option buttons, Those selections show up as a value. There are options which are selected as default using Javascript as per the code below.

Now on hitting Proceed I go to the next page. Now on the next page I have a back button and when I press the back button, What I want is the selections which I had made on the previous page should remain the same, What is happening on the other hand is, the default selected options are showing up.

I am using this button for the moment:

<input type="button" value="Back" onclick="window.history.back()" /> 

And this is how I am doing the selection:

<div class="panel panel-default">
    <div class="panel-heading">
     <h2 class="panel-title" id="selected_part_<%= part.id %>">


      <% @link_text =  "<b>#{part.name}</b> : <span class='selected_part_option'>#{part.options.detect{|o| o.is_default?}.try(:name)}</span>" %>

      <% if part.children.exists? %>
      <% part.children.each do |part_child| %>
      <% if part_child.display_type == "radio" || part_child.display_type == "dropdown" %> 
      <%# @link_text = @link_text + " | <span id='part_child_" + part_child.id.to_s + "'>" + part_child.options.first.name + "</span>" %>
      <% end %>
      <% end %>
      <% end %>
      <%= link_to raw(@link_text), "#collapse_part_#{part.id}", class: "collapser", "data-toggle" => "collapse", "data-parent" => "#accordion" %>
    </h2>
  </div>

Any idea how do I achieve what I want to? Thanks in advance.

The default behaviour of Firefox browser is to remember the form's input value. I think in your case, you may use some JavaScript which reset the form automatically, which makes lost the state that the browser remembered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM