FAQ Topic - How do I get a perl/asp/php variable into client-side js?

F

FAQ server

-----------------------------------------------------------------------
FAQ Topic - How do I get a perl/asp/php variable into client-side js?
-----------------------------------------------------------------------

Use the server-side language to generate the javascript:

var jsvar="<%= aspvar %>";
var jsvar="<?php echo $phpvar ?>";


===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.
 
E

Evertjan.

FAQ server wrote on 25 dec 2006 in comp.lang.javascript:
-----------------------------------------------------------------------
FAQ Topic - How do I get a perl/asp/php variable into client-side js?
-----------------------------------------------------------------------

Use the server-side language to generate the javascript:

var jsvar="<%= aspvar %>";

Perhaps a warning should be in place
against unforeseen inner double quotes and/or returns?
Some validation seems necesary, either in the programmers mind or in code.

btw: ASP "injection" could be either a bonus or a pest:

<script type='text/javascript'>
<% aspvar = "world.""; jsvar2 = ""Hello " %>
var jsvar="<% = aspvar %>";
alert( jsvar2 + jsvar );
var jsvar="<?php echo $phpvar ?>";

[Probably the same, I don't use php]
 
R

Randy Webb

Evertjan. said the following on 12/25/2006 9:51 AM:
FAQ server wrote on 25 dec 2006 in comp.lang.javascript:


Perhaps a warning should be in place
against unforeseen inner double quotes and/or returns?
Some validation seems necesary, either in the programmers mind or in code.

I don't even know why that entry is even in the FAQ. If a person needs
to know how to get the server to generate code the best place to ask
that is in the appropriate server side group.
 
E

Evertjan.

Randy Webb wrote on 25 dec 2006 in comp.lang.javascript:
Evertjan. said the following on 12/25/2006 9:51 AM:

I don't even know why that entry is even in the FAQ. If a person needs
to know how to get the server to generate code the best place to ask
that is in the appropriate server side group.

True!

UNLESS
the serveride part is also understood as j[ava]script
AND
the FAQ is also understood as covering serverside code.

EVEN THEN
the perl/php should be out.

SO
by all means leave it out.
 
V

VK

Evertjan. said:
UNLESS
the serveride part is also understood as j[ava]script
AND
the FAQ is also understood as covering serverside code.

There used to be a stable amount of questions at c.l.j. about "how to
communicate my PHP page with my JavaScript" or "my ASP page with my
JavaScript".
From my observations many ASP and especially PHP developers have a very
weak or no separation in their minds of 1) server-side processing
instructions, 2) resulting (X)HTML text source sent to client, 3)
client-side DOM tree resulted from that source and 4) javascript
instructions dealing with the resulted DOM. There is in existence a
"model of the world" where all this exists, equals and communicates at
one time and in one place, in some imaginary "super media" :) At least
JavaScript problems are stable reported with PHP code, and when asked
to post the actual resulting page there is often a sincere surprise
"but this _is_ the actual page" (see the archives).

So this FAQ could once be a "hint" to the right direction.
EVEN THEN
the perl/php should be out.

SO
by all means leave it out.

Sustained (whatever does my voice mean)

P.S. There is always the "chicken and eggs" question with removing a
FAQ: there are not such questions because FAQ is not relevant anymore -
or because everyone reads the FAQ so they don't ask here.

If c.l.j. gets filled with such questions in a months or two (I doubt
very much - but if) then it can be restored.
From the other side I don't know if the question with FAQ enumeration
and direct links is solved by the FAQ maintainer. If not then all this
can peacefully wait till after New Year to hassle with.
 
R

Randy Webb

VK said the following on 12/25/2006 5:43 PM:
Evertjan. said:
UNLESS
the serveride part is also understood as j[ava]script
AND
the FAQ is also understood as covering serverside code.

There used to be a stable amount of questions at c.l.j. about "how to
communicate my PHP page with my JavaScript" or "my ASP page with my
JavaScript".

And they now fall into 4.34 or 4.44, but as far as asking how to get a
variable into client side code, it just isn't seen.
weak or no separation in their minds of 1) server-side processing
instructions, 2) resulting (X)HTML text source sent to client, 3)
client-side DOM tree resulted from that source and 4) javascript
instructions dealing with the resulted DOM.

Are you one of those "PHP Developers"? :-X
So this FAQ could once be a "hint" to the right direction.

But this group is not the place to learn how to properly code on the server.
Sustained (whatever does my voice mean)

P.S. There is always the "chicken and eggs" question with removing a
FAQ: there are not such questions because FAQ is not relevant anymore -
or because everyone reads the FAQ so they don't ask here.

Or the third possibility - people are using libraries so they don't have
to learn what they are doing so they tend to ask in the library group
more than here.

and direct links is solved by the FAQ maintainer. If not then all this
can peacefully wait till after New Year to hassle with.

Would you mind repeating that in English?
 
V

VK

From the other side I don't know if the question with FAQ enumeration
Would you mind repeating that in English?

"FAQ enumeration" - FAQ numbering such as 1.1, 1.2, 1.3, 1.4, etc.

"the question with FAQ enumeration" - many times discussed problem of
that will happen if say FAQ 1.2 gets removed? With a normal automated
numbering 1.3 becomes 1.2, 1.4 becomes 1.3 etc.

This raises "the question with direct links" - many times discussed as
well. Say a link <http://www.jibbering.com/faq/index.html#1_4> in a
c.l.j. post may start pointing to some all another FAQ overnight -
after some FAQ removal and re-numbering.

If you are ready to work with these questions right now or if you have
a ready to use solution, then go ahead. Otherwise "this can peacefully
wait till after New Year to hassle with".
 
R

Randy Webb

VK said the following on 12/26/2006 1:18 PM:
"FAQ enumeration" - FAQ numbering such as 1.1, 1.2, 1.3, 1.4, etc.

"the question with FAQ enumeration" - many times discussed problem of
that will happen if say FAQ 1.2 gets removed? With a normal automated
numbering 1.3 becomes 1.2, 1.4 becomes 1.3 etc.

This raises "the question with direct links" - many times discussed as
well. Say a link <http://www.jibbering.com/faq/index.html#1_4> in a
c.l.j. post may start pointing to some all another FAQ overnight -
after some FAQ removal and re-numbering.

You may want to read the thread entitled "FAQ Proposed Anchor Names"
from 19 December. It deals - directly - with what you are asking about.
It even has several proposed "solutions" to the problem.

<URL:
http://groups-beta.google.com/group...t&q=Randy+Webb+anchor&rnum=1#384da883ea8f81c5>
 
V

VK

Randy said:
You may want to read the thread entitled "FAQ Proposed Anchor Names"
from 19 December. It deals - directly - with what you are asking about.
It even has several proposed "solutions" to the problem.

Yes, I've seen this discussion - I did not read out any final solution
out of it. Did you make your mind already for something or are you
still open for proposals?
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>,
Unless someone speaks up and can give a good reason for leaving that
entry in the FAQ, it will come out in 10.0 as a search for 4.18 in the
archives turns up 6 hits, the most recent being Jun 1, 2005 so it's not
much of a "Frequently Asked Question".

Maybe a note should be added in the FAQ about articles that have been
removed and any articles that have been removed could be redirected to
that entry.


One wonders why you thought that a search for "4.18" would suffice (as
your words imply). A questioner would be unlikely to include it, and an
answerer would not necessarily do so, since "It's answered in the FAQ"
would suffice.

Where a section of the FAQ, one which is substantially sound but deemed
unnecessary, is removed, it could be appended to another Web page, maybe
excljfaq.htm. It would then be available in case of need.

It's a good idea to read the newsgroup and its FAQ. See below.
 
R

Randy Webb

VK said the following on 12/27/2006 8:00 AM:
Yes, I've seen this discussion - I did not read out any final solution
out of it. Did you make your mind already for something or are you
still open for proposals?

I am still open to a proposal as long as it is feasible and not overly
complicated. The only thing that needs a proposal though is how to deal
with numbered anchors as the FAQ is going to a word anchor system and
will no longer have numbered anchors.
 
V

VK

Randy said:
I am still open to a proposal as long as it is feasible and not overly
complicated. The only thing that needs a proposal though is how to deal
with numbered anchors as the FAQ is going to a word anchor system and
will no longer have numbered anchors.

OK, I'll think then too... next year...

I first wanted to know if the question is open (I don't like to
discharge my brain cells for nothing, I don't have too many of them as
some people knows ;-)
 
R

Randy Webb

Dr J R Stockton said the following on 12/27/2006 9:22 AM:
In comp.lang.javascript message <[email protected]>,




One wonders why you thought that a search for "4.18" would suffice (as
your words imply). A questioner would be unlikely to include it, and an
answerer would not necessarily do so, since "It's answered in the FAQ"
would suffice.

Because most people that possess any intelligence at all would think
that the first place to start to answer the question of "How often does
this question get asked?" would realize that the best place to start
trying to determine that would be to search the archives for that entry.
And since a search for that entry returns just 6 hits in a 10 year
archive then anybody possessing any level of common sense would come to
the - sound - conclusion that it doesn't get asked very often.

Where a section of the FAQ, one which is substantially sound but deemed
unnecessary, is removed, it could be appended to another Web page, maybe
excljfaq.htm. It would then be available in case of need.

It takes longer to do all that than it does to simply answer the
question (which the correct answer would be "That is an
ASP/PHP/PERL/etc.. question and better asked in the appropriate
newsgroup"). So the answer is not even "substantially sound" as it
relates to the comp.lang.javascript newsgroup. And if you want to be
totally JRS about it, a better "correct" answer would be that it was
off-topic here.
 
R

Randy Webb

VK said the following on 12/27/2006 4:28 PM:
OK, I'll think then too... next year...

Don't give yourself too much of a headache trying to think about it :)
I first wanted to know if the question is open (I don't like to
discharge my brain cells for nothing, I don't have too many of them as
some people knows ;-)

In all likelihood the solution is going to be a simple array of
number>phrase entries that redirects to the appropriate entry along with
a div that gets some innerHTML put into it that explains to re-bookmark
the page. Any entries that do not exist anymore would get directed to an
entry along the lines of "I have an old bookmark, why doesn't it work
anymore?".
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Dr J R Stockton said the following on 12/27/2006 9:22 AM:

Because most people that possess any intelligence at all would think
that the first place to start to answer the question of "How often does
this question get asked?" would realize that the best place to start
trying to determine that would be to search the archives for that
entry.

Agreed. But it needs to be either an intelligent search or a complete
read-everything search; you have not indicated an intelligent method of
searching.

Now re-read what you have quoted, until you understand it.
 
R

Randy Webb

Dr J R Stockton said the following on 12/28/2006 6:25 PM:

So you agree with my conclusion? I am pleased to see that.
But it needs to be either an intelligent search

The search I used was intelligent. Your failure to admit that is a
reflection on you, not me. And no, I did not search simply for 4.18, the
search I used took me almost 4 hours to find 6 related posts to it.
or a complete read-everything search;

You do one, I will stand behind my own research.
you have not indicated an intelligent method of searching.

Nor will I explain to you, again, how I came to that conclusion. If you
want to do a "better" search for it, and produce results that
resoundingly prove mine wrong, you are simply quibbling again.

Beginning on January 1, 2007 I will be ignoring any posts from you
regarding FAQ Entries based on the last months history of you constantly
making it a personal attack, changing the subject, and not being able to
stay on task. When I feel the desire to check your posts for
intelligence discussion I may change my mind but don't bet your
retirement on it happening before February.
 
V

VK

VK said:
There used to be a stable amount of questions at c.l.j. about "how to
communicate my PHP page with my JavaScript" or "my ASP page with my
JavaScript".

From my observations many ASP and especially PHP developers have a very
weak or no separation in their minds of 1) server-side processing
instructions, 2) resulting (X)HTML text source sent to client, 3)
client-side DOM tree resulted from that source and 4) javascript
instructions dealing with the resulted DOM. There is in existence a
"model of the world" where all this exists, equals and communicates at
one time and in one place, in some imaginary "super media" :) At least
JavaScript problems are stable reported with PHP code, and when asked
to post the actual resulting page there is often a sincere surprise
"but this _is_ the actual page" (see the archives).

See
<http://groups.google.com/group/comp..._frm/thread/b7ebe5e84cfbdc6a/af753b1569a7fd2a>
for the "proof of concept". So maybe this FAQ is not as useless as
thought.
 
R

Randy Webb

VK said the following on 1/3/2007 12:10 PM:

See
<http://groups.google.com/group/comp..._frm/thread/b7ebe5e84cfbdc6a/af753b1569a7fd2a>
for the "proof of concept". So maybe this FAQ is not as useless as
thought.

Whether the entry is useless or not isn't even remotely addressed in
that thread. That thread is about trying to access Server variables from
the client and is way more closely related to <URL:
http://jibbering.com/faq/index.html#FAQ4_34> than it will ever be
related to getting a server variable into client code.
 
V

VK

Randy said:
Whether the entry is useless or not isn't even remotely addressed in
that thread.

I mean that the FAQ in discussion is the most "straight" hint that 1)
the environment where ASP/PHP processing instructions are executed and
2) the environment where client-side javascript is being run - they
have the same "native synchronious relations" as 1) barking dog in
England and 2) mooing cow in China.

However obvious it may be, the understanding still may pose problems in
some circumstances. This is why the FAQ may stay useful for quick
references.
 
R

Randy Webb

VK said the following on 1/3/2007 12:32 PM:
I mean that the FAQ in discussion is the most "straight" hint that 1)
the environment where ASP/PHP processing instructions are executed and
2) the environment where client-side javascript is being run - they
have the same "native synchronious relations" as 1) barking dog in
England and 2) mooing cow in China.

How you come up with that relation between the thread you mention and
the FAQ Entry in this thread is totally beyond me.
However obvious it may be, the understanding still may pose problems in
some circumstances. This is why the FAQ may stay useful for quick
references.

No, that is not why it may stay useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top