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 ?&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
*** 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 -- |
|
|||
|
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 > > > |
|
|||
|
*** 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 -- |
![]() |
| Thread Tools | |
| Display Modes | |
|
|