-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.

1
  • var trimmed = (<?php echo $fileTrimed ?>) Commented Apr 11, 2014 at 21:46

2 Answers 2

2

I think you're missing a single echo

this code :

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

Should look like :

var trimmed = (<?php echo $fileTrimed; ?>)
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 = (<?php echo $fileTrimed ?>) line and tried to print trimmed immediately after that line. The page remained blank. Is there another component I could be missing, please? Commented Apr 11, 2014 at 22:53
  • Ah, I have the answer thanks to another friend. For the record, you cannot have the (). Instead of (<?php echo $fileTrimed ?>),it should be "<?php echo $fileTrimed ?>" just like @Sahil Mittal posted below. Thank you for taking the time to respond, both of you. Commented Apr 12, 2014 at 0:21
0

Try this-

 var finalURL = firstURL + "<?php echo $fileTrimed; ?>" + secondURL;

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.