Jump to content

working with session


crazyswede

Recommended Posts

This is very frustrating. Using session I can store variables in the computer, and then recover them in the new instance Without having to pass them through the URL. But at that point it appears that I can only print the value of the variables, whereas I need to load that value into a variable that I can then manipulate and work with. W3schools help page Specifically shows  that can be done., but it does not work for me. Is there something I'm doing wrong?

----------------------------------

ExistContents = "Exist";

newContents= "new";

%>

<div id="result1"></div>

<script>

sessionStorage.setItem( "ExistContents", "<%Response.Write( ExistContents )%>" )

</script>

 

<div id="result2"></div>

<script>

sessionStorage.setItem( "newContents", "<%Response.Write( newContents )%>" )

</script>

 

<input type=hidden name= "to_do" value= "WriteEdit"  >

<input type="submit" value="Submit">

 

<%

} //23

 

if( to_do == "WriteEdit" )

{ //100

%>

<div id="result1"></div>

<script>

   document.getElementById("result1").innerHTML = sessionStorage.getItem("ExistContents");

</script>

 

<div id="result2"></div>

<script>

   document.getElementById("result2").innerHTML = sessionStorage.getItem("newContents");

</script>

[So far all works great!]

 

<div id="result1"></div>

<script>

    var file1 = sessionStorage.getItem("ExistContents" ) <---  W3schools help page Specifically shows that can be done., but it does not work for me. Down below I print the value of file1, but I get undeclared identifier. 😩

</script>

 

<div id="result2"></div>

<script>

    var file2 = String( sessionStorage.getItem( "newContents" ) ) <-- I tried something else, here, which didn't work either

</script>

<%

Response.Write( "file1= "+ file1 +"<br>" )

Response.Write("file2= "+ file2 +"<br>" )

Edited by crazyswede
Link to comment
Share on other sites

Hmmm... why do you expect server-side code to be able to see client-side Javascript variables? Server-side code runs and then the browser loads the page and then client-side Javascript runs.

Link to comment
Share on other sites

var file1 is declared inside javascript, if you try console.log(file1) it should work .

when you call Response.Write("file1=" + file1) this is an ASP call which cannot access the variable File1 (which is a javascript variable)

Good luck

Link to comment
Share on other sites

I’m Working with classic asp.

Great! 😀 Can you help me out with an address where I can study console()?  I apparently don't know how to do this. I Google Console() and I get a bunch of links. I click a link and I just get more likes. Click again and I just get more links. . . And on and on and on.

On 9/30/2018 at 4:41 AM, john_jack said:

 

Link to comment
Share on other sites

One thing that you might be confusing is that client-side session storage is not the same as server-side session storage. Server-side session storage is secure, while Javascript sessionStorage is just a variation of localStorage which is a replacement for old-fashioned cookies.

Server:

https://www.w3schools.com/asp/asp_sessions.asp

Client:

https://www.w3schools.com/html/html5_webstorage.asp

Link to comment
Share on other sites

The Console is found differently in different browsers.

In my old Firefox browser I simply click on the wrench in the bottom-right corner of my browser window.  You can also find it in the Web Developer submenu of the Tools menu.  It will say Web Console.

In my old Chrome browser I click on the Developer submenu of the View menu and then on Javascript Console.

Your initial view of the Console page will likely be intimidating, but do not be put off, for the Console page is far too powerful a tool to simply discount, because you do not understand it at first.

After you have opened the Console page look for your cursor and enter some Javascript that includes some of the variables on your loaded page and watch what happens.

Then go to your source code and enter the following with the appropriate substitutes into the body of your script.  It will have no effect on your script, but it will tell you whether your script is doing what you think it should.

console.log('variable_name: ' + variable_name);

The result will appear in your Web Console page.  From this you can determine the values of your variables as they are being created.

Roddy

Link to comment
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
×
×
  • Create New...