Solved

javascript not refilling after going back

Posted on 2013-12-30
8
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 43

Expert Comment

by:Rob
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 43

Expert Comment

by:Rob
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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
 
LVL 43

Expert Comment

by:Rob
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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…
Suggested Courses

623 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