parsing php inside javascript

This is a discussion on parsing php inside javascript within the alt.comp.lang.php forums, part of the PHP Programming Forums category; <script language = "javascript"> foto1 = new Image; foto1.src = "../img_models/" + <?php echo $idm_1.jpg ?&...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-30-2003
Marzia Coccia
 
Posts: n/a
Default parsing php inside javascript

<script language = "javascript">
foto1 = new Image;
foto1.src = "../img_models/" + <?php echo $idm_1.jpg ?> ;

it doesn't work, because of the parsing php.
Please help me!
Thanks a lot, marzia



Reply With Quote
  #2 (permalink)  
Old 10-30-2003
Alvaro G Vicario
 
Posts: n/a
Default Re: parsing php inside javascript

*** Marzia Coccia wrote/escribió (Thu, 30 Oct 2003 16:13:34 +0100):
> foto1.src = "../img_models/" + <?php echo $idm_1.jpg ?> ;
>
> it doesn't work, because of the parsing php.


Parsed PHP will produce this JavaScript code:

foto1.src = "../img_models/"+foo.jpg ;

My suggestion:

foto1.src = "../img_models/<?php echo urlencode($idm_1)?>.jpg";


--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Reply With Quote
  #3 (permalink)  
Old 10-30-2003
DM
 
Posts: n/a
Default Re: parsing php inside javascript

Well what error does it give?
Try ending your PHP statement with a ;
Is the .jpg part of the variable name ? or do you mean to append that on the
end of the file name ?

Maybe try:

<script language = "javascript">
foto1 = new Image;
foto1.src = "../img_models/" + <?php echo ($idm_1); ?> + ".jpg";

also, im not sure if you would need quotes around the php bit so the JScript
reads it as a string (once it is parsed), but im not sure how that would
effect the parsing, maybe try

<script language = "javascript">
foto1 = new Image;
fle = <?php echo (' "' . $idm_1 . '" ' ); ?> // single quote,
double quote, single quote.
foto1.src = "../img_models/" + fle + ".jpg";

"Marzia Coccia" <m.coccia@ikaro.com> wrote in message
news:bnr99g$puf$1@fata.cs.interbusiness.it...
> <script language = "javascript">
> foto1 = new Image;
> foto1.src = "../img_models/" + <?php echo $idm_1.jpg ?> ;
>
> it doesn't work, because of the parsing php.
> Please help me!
> Thanks a lot, marzia
>
>
>



Reply With Quote
  #4 (permalink)  
Old 10-30-2003
Alvaro G Vicario
 
Posts: n/a
Default Re: parsing php inside javascript

*** Alvaro G Vicario wrote/escribió (Thu, 30 Oct 2003 16:30:47 +0100):
> Parsed PHP will produce this JavaScript code:
>
> foto1.src = "../img_models/"+foo.jpg ;


Sorry, one correction:

foto1.src = "../img_models/"+foojpg ;

(given that $idm_1's value is "foo" and jpg is an undefined constant)


--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:39 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0