This topic is locked

javascript onload event - session variables

6/16/2023 1:16:06 PM
PHPRunner General questions
A
Ace Drummond author

How to access session variables in javascript onload event?
I have session variable I can access in .php $_SESSION["p_chapter"]
I want to access it with javascript onload event.
Previous forum response to this points me to use set proxy value; however, I don't understand how to do this for a session variable.
Appreciate some assistance thanks//

Admin 6/16/2023

Check the manual one more time:
https://xlinesoft.com/phprunner/docs/setproxyvalue.htm
The first argumant is the name of the variable. Can be any name. The second argument is the value, can be a session variable.

A
Ace Drummond author 6/26/2023

Sorry. I looked at it and guessed at how to form the code and getting nowhere!
I need to retrieve a session variable to use in javascript on load event.
One of the session variables is $_SESSION["p_chapter]
Can you please advise how to code this as the documentation is not helping. Thanks//

Admin 6/27/2023

Show us your code, we'll figure this out together.

A
Ace Drummond author 6/28/2023

This is what I am tryingto do
// I have 3 $_SESSION variables $_SESSION["p_chapter"], $_SESSION["p_role"], $_SESSION["p_status"]
// I am trying to put them into inpit fields on the page
// I've done this successfully using the variables passed via URL ands I know that works
// What I am trying to learn is how to access session variablesa so I can put tthem into fields on the page
// I am trying to follow the examples from the manual and adapt for SESSION variables
// Obviously the following code is invalid and the problem is how to code this to retrieve the session variable(s)
// Once I know how to do one then the other should follow easily.
$pageObject->setProxyValue("chapter", '<%=session["p_chapter"]%>');
alert(proxy['chapter']);
document.getElementById('chapter').setAttribute('value', chapter);
document.getElementById('role').setAttribute('value', role);
document.getElementById('status').setAttribute('value', status);
Thanks//

Admin 6/29/2023

Which part of this code goes to BeforeDisplay event? You are mixed the code from different events here and it is not easy to follow.

A
Ace Drummond author 6/29/2023

For sure I am missing something! Might looked mixed up too, but that is why I ask for some input.
The issue I am trying to address might have another solution, but when I asked about it responses were nil - so here goes again.
I have some fields that are supported by parameters such that for a field like chapter the value storted in the member record is 'P' which would show up as 'PikesPeak' in my case.
I am building an application where the member can manage his own profile, but may not change certain fields like in this case 'chapter'.
If I show the field in the record it shows up as 'P' in readonly mode. If it is a lookup then the value 'PikesPeak' shows up but it is not read only (or I don't know how to make it read only.)
So what I did was create a small process that gets the user data and places the value I want to display in a session variable.
I then modified the member profile page adding an input field that is read only called in this case 'chapter'.
What I want to do is populate that input field with the session variable in this case 'PikesPeak'
I trying to do this in the javascript onload event.
I did build the same capability using the value in a URL and it worked as needed. I even posted that solution on this forum (again nil comments.)
What I am trying to learn here is how to do the same thing only using a session variable.
By no stretch of the imagination am I a skilled javascript coder - I admit that try to learn and somehow muddle by.
I've spent numerous hours on this and it is one of those things I just want to solve because it will help me down the road.
A: If there is a better way to solve the initial problem I've not found it.
B: How do I get session variable information onto the screen where I needed with some other method other than adding an 'input read only field'
Frankly, I've been able to make this development software do everything I want. Most often solve my own issues or find solutions here or on the web, but this one is ongoing.
Great software, much better and easier to learn then the previous platform I used.
Thanks//

Admin 6/30/2023

Unfortunately this doesn't help much as I need to understand what code do you place and where. I'll try one more time.
According to the manual https://xlinesoft.com/phprunner/docs/setproxyvalue.htm, this approach requires code in two events. PHP code goes to BeforeDisplay event and Javascript code goes to JavascriptOnLoad event of the same page.
So, we need to see the code in both events. Post your code here, explaining where each piece of code was placed.

A
Ace Drummond author 7/5/2023

I am frustrated that this goes nowhere - so I'll try a different approach.
restating my issue:
I want to display fields on a member profile edit screen that the<em> user can not change</em> i.e. chapter, role and status. Normally I would do this with making those fields Read Only, but since these fields are supported by parameters example: member record has a code that gives me the code description on look up. (I accomplished this code lookup in another procedure and passed the results as URL parameters to make this work for me.)
IF there were away to display those code descriptions as read only other that what I am doing I am listening!
My solution so far is to edit HTML to add <em>read only</em> input fields and populate them using URL paramters passed to my edit screen. THIS WORKS - it is not elegant, but it works.
Here is the code in<em> javascript on load event</em>:
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
var chapter = getUrlVars()["c"];
var role = getUrlVars()["r"];
var status = getUrlVars()["s"];
//alert(chapter + role + status)
document.getElementById('chapter').setAttribute('value', chapter);
document.getElementById('role').setAttribute('value', role);
document.getElementById('status').setAttribute('value', status);
What I am asking is <em>how would I substitute SESSION variables in this instance instead of URL variables</em>?
In my opinion, I am missing something here as others must have this same need, but all we seem to be doing is going in circles here.
If you can advise I'd appreciate it. If not thanks anyway and let's just close this ticket as it is going nowhere right now.//

Admin 7/5/2023

How do you expect us to help you if you never post the info requested?

A
Ace Drummond author 7/6/2023

Not helpful and very disappointing.//