PHP within javascript

PHP within javascript

am 27.08.2007 04:00:11 von Morlaath

Is there a way to embed php within javascript code? I know that php is
server side and js is client side. For instance when working with jsp,
you can imbed jsp scriptlets within the js code.

e.g

Re: PHP within javascript

am 27.08.2007 04:02:41 von Morlaath

On Aug 26, 9:00 pm, Morla...@gmail.com wrote:
> Is there a way to embed php within javascript code? I know that php is
> server side and js is client side. For instance when working with jsp,
> you can imbed jsp scriptlets within the js code.
>
> e.g
>
>

Lol ... the example above isn't quite right. Replace var bar = <
%=(java variable)%> with <%= String bar = "test"; %>, then it would
work.

Re: PHP within javascript

am 27.08.2007 04:07:29 von Morlaath

Third time is the charm ;)

Re: PHP within javascript

am 27.08.2007 14:33:19 von Jeff North

On Mon, 27 Aug 2007 02:00:11 -0000, in comp.lang.php
Morlaath@gmail.com
<1188180011.507936.75090@r34g2000hsd.googlegroups.com> wrote:

>| Is there a way to embed php within javascript code? I know that php is
>| server side and js is client side. For instance when working with jsp,
>| you can imbed jsp scriptlets within the js code.
>|
>| e.g
>|
>|


-- ------------------------------------------------------------ -
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
-- ------------------------------------------------------------ -

Re: PHP within javascript

am 27.08.2007 19:14:38 von Morlaath

On Aug 27, 7:33 am, Jeff North wrote:
> On Mon, 27 Aug 2007 02:00:11 -0000, in comp.lang.php
> Morla...@gmail.com
>
>
>
> <1188180011.507936.75...@r34g2000hsd.googlegroups.com> wrote:
> >| Is there a way to embed php within javascript code? I know that php is
> >| server side and js is client side. For instance when working with jsp,
> >| you can imbed jsp scriptlets within the js code.
> >|
> >| e.g
> >|
> >|
>
>
> -- ------------------------------------------------------------ -
> jnort...@yourpantsyahoo.com.au : Remove your pants to reply
> -- ------------------------------------------------------------ -

Anytime I embed php within javascript with the tags the php
executes as soon as the page is loaded. So for instance if I have
something like the following.

//Javascripts
function foo() {

}



The 'session_destyoy()" is called as soon as the page is loaded,
instead of when you click on the button.

Re: PHP within javascript

am 27.08.2007 19:42:40 von Michael Fesser

..oO(Morlaath@gmail.com)

>Anytime I embed php within javascript with the tags the php
>executes as soon as the page is loaded.

Sure, because that's how it works. PHP is server-side. When the page
arrives in the browser, the execution of the PHP script is finished
already.

>So for instance if I have
>something like the following.
>
>//Javascripts
>function foo() {
>
>}
>
>
>
>The 'session_destyoy()" is called as soon as the page is loaded,
>instead of when you click on the button.

Your button click would have to invoke another server-side script to
kill the session, something like . No
need for JavaScript here.

Micha

Re: PHP within javascript

am 27.08.2007 19:55:39 von Shelly

wrote in message
news:1188234878.670476.139660@50g2000hsm.googlegroups.com...
> Anytime I embed php within javascript with the tags the php
> executes as soon as the page is loaded. So for instance if I have
> something like the following.
>
> //Javascripts
> function foo() {
>
> }
>
>
>
> The 'session_destyoy()" is called as soon as the page is loaded,
> instead of when you click on the button.
>

Try

function foo() {


to write the javascript piece in the html area.

Re: PHP within javascript

am 27.08.2007 19:55:55 von Jerry Stuckle

Morlaath@gmail.com wrote:
> On Aug 27, 7:33 am, Jeff North wrote:
>> On Mon, 27 Aug 2007 02:00:11 -0000, in comp.lang.php
>> Morla...@gmail.com
>>
>>
>>
>> <1188180011.507936.75...@r34g2000hsd.googlegroups.com> wrote:
>>> | Is there a way to embed php within javascript code? I know that php is
>>> | server side and js is client side. For instance when working with jsp,
>>> | you can imbed jsp scriptlets within the js code.
>>> |
>>> | e.g
>>> |
>>> |
>>
>> -- ------------------------------------------------------------ -
>> jnort...@yourpantsyahoo.com.au : Remove your pants to reply
>> -- ------------------------------------------------------------ -
>
> Anytime I embed php within javascript with the tags the php
> executes as soon as the page is loaded. So for instance if I have
> something like the following.
>
> //Javascripts
> function foo() {
>
> }
>
>
>
> The 'session_destyoy()" is called as soon as the page is loaded,
> instead of when you click on the button.
>

That's right. PHP is server side, not client side. It will always be
executed before (or as) the page is sent to the browser. There is no
way to call a PHP function from javascript directly.

The only way you could do it is with something like AJAX, which would
make a call to the server to perform the action.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: PHP within javascript

am 27.08.2007 20:03:12 von Morlaath

On Aug 27, 12:55 pm, Jerry Stuckle wrote:
> Morla...@gmail.com wrote:
> > On Aug 27, 7:33 am, Jeff North wrote:
> >> On Mon, 27 Aug 2007 02:00:11 -0000, in comp.lang.php
> >> Morla...@gmail.com
>
> >> <1188180011.507936.75...@r34g2000hsd.googlegroups.com> wrote:
> >>> | Is there a way to embed php within javascript code? I know that php is
> >>> | server side and js is client side. For instance when working with jsp,
> >>> | you can imbed jsp scriptlets within the js code.
> >>> |
> >>> | e.g
> >>> |
> >>> |
> >>
> >> -- ------------------------------------------------------------ -
> >> jnort...@yourpantsyahoo.com.au : Remove your pants to reply
> >> -- ------------------------------------------------------------ -
>
> > Anytime I embed php within javascript with the tags the php
> > executes as soon as the page is loaded. So for instance if I have
> > something like the following.
>
> > //Javascripts
> > function foo() {
> >
> > }
>
> >
>
> > The 'session_destyoy()" is called as soon as the page is loaded,
> > instead of when you click on the button.
>
> That's right. PHP is server side, not client side. It will always be
> executed before (or as) the page is sent to the browser. There is no
> way to call a PHP function from javascript directly.
>
> The only way you could do it is with something like AJAX, which would
> make a call to the server to perform the action.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

I was hoping it would work something like jsp, which I deal with all
day at work. You can embed jsp scriptlets within js code and it will
not be executed until the the js function is called. Jsp is also
server side ;P

Re: PHP within javascript

am 28.08.2007 02:26:14 von Jerry Stuckle

Morlaath@gmail.com wrote:
> On Aug 27, 12:55 pm, Jerry Stuckle wrote:
>> Morla...@gmail.com wrote:
>>> On Aug 27, 7:33 am, Jeff North wrote:
>>>> On Mon, 27 Aug 2007 02:00:11 -0000, in comp.lang.php
>>>> Morla...@gmail.com
>>>> <1188180011.507936.75...@r34g2000hsd.googlegroups.com> wrote:
>>>>> | Is there a way to embed php within javascript code? I know that php is
>>>>> | server side and js is client side. For instance when working with jsp,
>>>>> | you can imbed jsp scriptlets within the js code.
>>>>> |
>>>>> | e.g
>>>>> |
>>>>> |
>>>>
>>>> -- ------------------------------------------------------------ -
>>>> jnort...@yourpantsyahoo.com.au : Remove your pants to reply
>>>> -- ------------------------------------------------------------ -
>>> Anytime I embed php within javascript with the tags the php
>>> executes as soon as the page is loaded. So for instance if I have
>>> something like the following.
>>> //Javascripts
>>> function foo() {
>>>
>>> }
>>>
>>> The 'session_destyoy()" is called as soon as the page is loaded,
>>> instead of when you click on the button.
>> That's right. PHP is server side, not client side. It will always be
>> executed before (or as) the page is sent to the browser. There is no
>> way to call a PHP function from javascript directly.
>>
>> The only way you could do it is with something like AJAX, which would
>> make a call to the server to perform the action.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> I was hoping it would work something like jsp, which I deal with all
> day at work. You can embed jsp scriptlets within js code and it will
> not be executed until the the js function is called. Jsp is also
> server side ;P
>

The last time I looked, if it was embedded in javascript it was executed
client side - and the client must have java available.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================