Solved

javascript not refilling after going back

Posted on 2013-12-30
8
346 Views
Last Modified: 2014-01-02
I have a form that select box #2 gets populated after select #1 is picked.
then they click submit and get brought to a longer page.
If someone uses the back button on their browser, the box #1 is still selected, but my javascript populated second box is now empty.
How can I set it up ,if someone just hits back that second box will populate with the first box information?
0
Comment
Question by:rivkamak
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39747626
It would all depend on how you handle your state.  Ideally this is done server side via sessions. What are you using server side?
To just suggest an answer based on this one example will not work if the Javascript isn't specific to the page. Eg, when the page loads you could test to see if the first drop down has a selected value and call the same function that is called with the Onchange event. But this could cause issues if you re use the Javascript code on other pages. Very hard to say without seeing how and what you've done to code this
0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 250 total points
ID: 39747925
You could add an onload event that charges the data as the populating function does.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39748012
That's right, exactly what I said

when the page loads you could test to see if the first drop down has a selected value and call the same function that is called with the Onchange event.

However, what works for one page may not work with the next.
0
 

Author Comment

by:rivkamak
ID: 39748602
I don't want the onchange event to run again, because it just loads 10 items in a select box.
I need to know which item was selected.

I tried putting this code
 <script>
      $( document ).ready(function() {
if ($('#make').val != "") {
$('#model').val(<%=session("usermodel")%>);
}
});
</script>

Open in new window

I set that session on the second page.
When you click back though the page doesn't populate again , it doesn't fully reload, so it doesn't recognize that session variable.

Is there any way to get what the selected index would have been on that second box?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39749561
Val us a function not a property so you'll need the brackets (). Also missing were the inverted commas around the session variable to indicate a string and not a variable
<script>
      $( document ).ready(function() {
if ($('#make').val() != "") {
$('#model').val('<%=session("usermodel")%>');
}
});
</script>

Open in new window

0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 250 total points
ID: 39749805
Just trigger the change event onload

$(function() {
  $('#make').change();
});
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39749970
That's what I've argued on post 39747925...
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39749998
You argue to re-execute the function. It is much simpler, just trigger the change event on the select
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now