-4

I am trying to load a file which is being uploaded using PHP script. I have assigned a variable for the location of the uploaded file $tra = basename( $_FILES['userfile']['name']); and trying to give it as a input for the java script

<script type="text/javascript">
var a = <?php echo $tra; ?>;   
</script>
<script type="text/javascript" src="C:/xampp/htdocs/new/jmol/Jmol.js"></script>

But its showing an error Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\example.php on line 30 and line number 30 is

<script type="text/javascript">
7
  • Could you show us more of the surrounding JS code? There is probably an extra angle bracket in there somewhere. Commented Jul 10, 2012 at 11:52
  • 2
    A parse error like this is usually an indication that there's something wrong before the identified line. It gave up parsing when it got to something it didn't recognize, but it didn't recognize it because of what came before. Commented Jul 10, 2012 at 11:53
  • 1
    @NikolaK.: It's not quite exact. This person is having problems with PHP syntax, entirely outside of the intended goal of emitting a value to JavaScript (which should work fine here if his other PHP code were made syntactically correct). Commented Jul 10, 2012 at 11:56
  • 1
    Hey this is the current weekly update of that ever-recurring question… Commented Jul 10, 2012 at 12:02
  • 1
    @NikolaK. = close but as David pointed out this is a syntax issue rather than "I have no clue at all". Commented Jul 10, 2012 at 22:52

1 Answer 1

1

try this:

<script type="text/javascript">
var a = '<?php echo $tra; ?>';   
</script>

You need to enclose with '' to asign a string to a javascript variable. If you are trying to assign a number it should work without the quotes, unless there's an error in your PHP.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.