Jump to content

Question

I have a form containing two pulldowns (Carrier and Trailer). Along with them, I have two links allowing me to add new Carriers and respective Trailers.

Each field works fine, except for the fact that when they close and redisplay the main form, any data previously entered is cleared. So the first 4 fields where I have entered data are cleared.

The Javas script I am using that I got from a Caspio doc is:

<script>
window.close();
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
}
</script>

I am not a Java person at all so I am wondering if this script can be modified and a way where the newly entered data is stored in the respective table, the window closed and the newly entered data shows up in the recently updated drop down.

 

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi @dmyoungsal

That is interesting. I am not certain if this would work, but you can give it a try.

When the page refreshes it is possible to retain the user's input by using the JavaScript window.localStorage().

Here's a brief example on how to use window.localStorage().

var someVar = localStorage.getItem("someVarKey");

You may replace the var "someVar" with your actual fields and see if it works.

So in your case:

<script>

var someVar = localStorage.getItem("someVarKey");

window.close();
if (window.opener && !window.opener.closed) {
window.opener.location.reload();

}

</script>

Please note that, whatever you call in .setItem() it will call .toString() so only string values can be stored in this method, but in an event that you need to work with different data type, you can use JSON.stringify and JSON.parse.

References:

Browser Storage - https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage
localStorage - https://developer.mozilla.org/en-US/docs/DOM/Storage#localStorage
JSON - https://developer.mozilla.org/en-US/docs/JSON
Browser Storage compatibility - http://caniuse.com/namevalue-storage
Storing objects - Storing Objects in HTML5 localStorage

I suggest that you read  the references thoroughly so you can understand the full capability and usage of the localStorage().

Cheers,

~ H

Share this post


Link to post
Share on other sites
  • 0

Alternatively, you may also use window.name()

Syntax:

string = window.name;
window.name = string;

to test this out, you may press F12 to show the browser's dev tools, then locate the console tab and write the following:

Example:

window.name = "lab_view";

After that, press enter and reload the page. When the page is loaded go to the dev tool's console tab again, and type window.name; you should see the value which is "lab_view"

You see, the page has been refreshed but the value is retained. 

References:

Stackoverflow:  https://stackoverflow.com/questions/10567847/window-name-as-a-data-transport-a-valid-approach

MDN: https://developer.mozilla.org/en-US/docs/Web/API/Window/name

 

Cheers,

~ H

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×