Jump to content
  • 0

Java


dmyoungsal

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.

 

 

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...