-1

I'm working on a project where the opening page is .php. It allows users to select a map file they want to view. That page sends the variable to another page that has javascript on it. I'm not a js programmer, so I'm struggling here. The problem is that I need to apply that variable from the php page to a concatenated string in the js. Here's what I have...

<script>
<?php 
  $filename = $_GET["filename"];
  $fileTrimed = str_replace(".mxd", "", $filename);
?> 
var trimmed = (<?php $fileTrimed ?>)
var firstURL = "http://localhost:6080/arcgis/rest/";
var secondURL = "/MapServer";
var finalURL = firstURL + trimmed + secondURL;

I have also tried it as...

?>
var firstURL = "http://localhost:6080/arcgis/rest/";
var secondURL = "/MapServer";
var finalURL = firstURL + $fileTrimed + secondURL;

I appreciate any help y'all can offer.

Iakona
  • 157
  • 2
  • 12

2 Answers2

2

I think you're missing a single echo

this code :

var trimmed = (<?php $fileTrimed ?>)

Should look like :

var trimmed = (<?php echo $fileTrimed; ?>)
Raikeru
  • 31
  • 2
  • Raikeru, it appears everyone agrees with you. However, it does not seem to work. I even moved the code to a test page to isolate it. I commented out the "trimmed" variable and was able to get the other variables to print. I then only uncommented the var trimmed = () line and tried to print trimmed immediately after that line. The page remained blank. Is there another component I could be missing, please? – Iakona Apr 11 '14 at 22:53
  • Ah, I have the answer thanks to another friend. For the record, you cannot have the (). Instead of (),it should be "" just like @Sahil Mittal posted below. Thank you for taking the time to respond, both of you. – Iakona Apr 12 '14 at 00:21
0

Try this-

 var finalURL = firstURL + "<?php echo $fileTrimed; ?>" + secondURL;
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90