473,569 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

accessing javascript variables within psp code

Hello all,

Question: Is there any way to access a javascript variable from
within psp code?
I'm aware of how to do the reverse of this (js_var='<%=psp _var%>').
Here's a non-working example of what I'm trying to do:
- - - (begin example) - - -
function Test(txt)
{
a = confirm('Are you sure you want to delete '+txt+'?')
if (a)
{
//The problem is getting the value of js variable 'txt' recognized in
"psp space".
<%
os.remove( os.path.join(os .path.dirname(r eq.filename), '../notes/'+
%>txt<%) )
%>
}
}
- - - (end example) - - -

FYI, I've already found a workaround for the above example (by placing
a "get" variable in the URL, reloading the page, and having psp check
for the existence of that variable before proceeding with deleting the
appropriate file) but I'd still like this general capability for
future projects. I've searched several forums, websites, etc. and
the
answer has aluded me for two days now. I'm new to apache, mod_python,
and javascript, so this may be ridiculously simple.

Since this is my first post on google groups, I'd also appreciate any
helpful suggestions on how to best go about getting answers quickly
(so let me know if there's a more appropriate forum/method/etc.)

Thanks for any help you can provide.

(This is copied from a message I originally posted to the mod_python
group.)

Jul 18 '07 #1
3 2416
On Wed, 18 Jul 2007 04:29:27 +0300, BAnderton <bl************ @gmail.com>
wrote:
>
Hello all,

Question: Is there any way to access a javascript variable from
within psp code?
I'm aware of how to do the reverse of this (js_var='<%=psp _var%>')..
Here's a non-working example of what I'm trying to do:
- - - (begin example) - - -
function Test(txt)
{
a = confirm('Are you sure you want to delete '+txt+'?')
if (a)
{
//The problem is getting the value of js variable 'txt' recognized in
"psp space".
<%
os.remove( os.path.join(os .path.dirname(r eq.filename), '../notes/'+
%>txt<%) )
%>
}
}
- - - (end example) - - -

FYI, I've already found a workaround for the above example (by placing
a "get" variable in the URL, reloading the page, and having psp check
for the existence of that variable before proceeding with deleting the
appropriate file) but I'd still like this general capability for
future projects. I've searched several forums, websites, etc. and
the
answer has aluded me for two days now. I'm new to apache, mod_python,
and javascript, so this may be ridiculously simple.

Since this is my first post on google groups, I'd also appreciate any
helpful suggestions on how to best go about getting answers quickly
(so let me know if there's a more appropriate forum/method/etc.)

Thanks for any help you can provide.

(This is copied from a message I originally posted to the mod_python
group.)
Only with ajax.
Jul 18 '07 #2
BAnderton a écrit :
Hello all,

Question: Is there any way to access a javascript variable from
within psp code?
Short answer : no (or at least: not directly). And it has nothing to do
with PSP.

<OT>
Long answer: this has to do with the http protocol. Things go like this:

1/ the client (usually the browser) send a request (via typing an url in
the address bar, clicking a link, posting a form...)

2/ the server process the request (this is where your psp - or any other
server-side - code is executed) and send back a response (in your case,
what has been generated by the psp code).

3/ the client do something (usually: display) the response. This is
where Javascript - if any, and if supported by the client - is executed.

From the server's POV, once the response is sent, the transaction is
finished.

The only way to have client-side javascript communicate with the server
is via the XmlHttpRequest object (IOW : ajax). This allow javascript
code to send a request to a server without reloading the whole page.
</OT>

(snip)
>
FYI, I've already found a workaround for the above example (by placing
a "get" variable in the URL, reloading the page, and having psp check
for the existence of that variable before proceeding with deleting the
appropriate file)
<OT>
Beware, GET request should *not* have such side-effects on the server. A
GET request is meant - as the name implies - to get data from the
server. Use a POST request instead.

If you're going to do web development, reading the http RFC might be
helpful...
</OT>
but I'd still like this general capability for
future projects.
Then you have to learn how to use XmlHttpRequest.
I've searched several forums, websites, etc. and
the
answer has aluded me for two days now. I'm new to apache, mod_python,
and javascript, so this may be ridiculously simple.

Since this is my first post on google groups,
<OT>
Small correction : you're not posting "on" google groups, you're posting
on usenet *from* google groups. Most people prefer to access usenet via
a newsreader.
</OT>
I'd also appreciate any
helpful suggestions on how to best go about getting answers quickly
http://www.catb.org/~esr/faqs/smart-questions.html

And remember that usenet is definitively not an help desk. No one get
paid for answering your questions.

HTH
Jul 18 '07 #3
On Wed, 2007-07-18 at 01:29 +0000, BAnderton wrote:
Hello all,

Question: Is there any way to access a javascript variable from
within psp code?
I'm aware of how to do the reverse of this (js_var='<%=psp _var%>').
Here's a non-working example of what I'm trying to do:
- - - (begin example) - - -
function Test(txt)
{
a = confirm('Are you sure you want to delete '+txt+'?')
if (a)
{
//The problem is getting the value of js variable 'txt' recognized in
"psp space".
<%
os.remove( os.path.join(os .path.dirname(r eq.filename), '../notes/'+
%>txt<%) )
%>
}
}
- - - (end example) - - -

FYI, I've already found a workaround for the above example (by placing
a "get" variable in the URL, reloading the page, and having psp check
for the existence of that variable before proceeding with deleting the
appropriate file) but I'd still like this general capability for
future projects. I've searched several forums, websites, etc. and
the
answer has aluded me for two days now. I'm new to apache, mod_python,
and javascript, so this may be ridiculously simple.
>From your vague description it sounds like the contents of your
JavaScript variable come from the server to begin with. In that case
it's easier and more secure to "remember" the correct value on the
server instead of sending it to the client and trusting the client[*] to
send the same value back.

To store variables on the server side between requests by the same
client, use session variables.
[*] A basic premise of web programming is that the client can't be
trusted: Don't trust that maximum form field sizes will be honored,
don't trust that cookies won't be changed, don't trust that GET
parameters won't be changed, don't trust that hidden form fields won't
be changed, etc.

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net
Jul 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2300
by: J. J. Cale | last post by:
I want to access the DOM. Can something like this be done with PHP or a combination of PHP/JAVASCRIPT? not tested! <html><head><title>DOM test</title> <?php $inFileName = 'test.js'; $outFileName = 'jk.js'; function doIt() { $dd = getElementById('first'); $dd.innerText=$outFileName; }
3
12378
by: Peter | last post by:
Hello, Two newbie questions: 1) I have a javascript file with a function in it. From this function I want to access a variable in another javascript file -which is not inside a function. I have tried many combinations to do this, but has yet to try the right one. How is it done? 2) What kinds of file operations can be done in...
22
4584
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and...
8
2732
by: dwok | last post by:
I have been wondering this for a while now. Suppose I have a class that contains some private member variables. How should I access the variables throughout the class? Should I use properties that expose the variables or is it OK to just access the variables directly? Keep in mind that I am talking about accessing the variables from within the...
5
2471
by: TS | last post by:
is it preferred to access member variables directly in code, on the page that declared them, versus going thru a property accessor? I would think that since theres no security concerns or anything it would be more efficient to access directly. I also don't think that you would need to do any special validation since the class developer knows...
12
11696
by: Steve Blinkhorn | last post by:
Does anyone know of a way of accessing and modifying variables declared static within a function from outside that function? Please no homilies on why it's bad practice: the context is very particular and involves automatically generated code. I know several other ways of attacking my problem, but this would be the cleanest if it could be...
10
12784
by: John Passaniti | last post by:
(Note: This is not the same message I posted a week or so ago. The problem that prevented my previous attempt to work was a silly error in the template system I was using. This is a problem involving variable scope in JavaScript.) I have a lot of code that generates HTML on the fly. This code has tags with id attributes derived from...
1
25639
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that...
4
1839
by: MartinRinehart | last post by:
I've written a short article explaining closures in JavaScript. It's at: http://www.martinrinehart.com/articles/javascript-closures.html I think I've understood. I look forward to your constructive critique.
0
7721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7941
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7699
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5520
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3669
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.