Solved

javascript not refilling after going back

Posted on 2013-12-30
8
358 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
NOT having JQuery DataTable Columns Sort 7 36
Jquery Calculation 3 42
Slow Down an Animation 3 29
Undefined variable with $_POST in PHP 5 40
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

751 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