user1964964
user1964964

Reputation: 255

syntax error missing ), don't know where to place it in order to echo input

I want to know what is the correct way of display a text input in an echo in the code below because nothing is being outputted:

<script language="javascript" type="text/javascript">
  window.top.stopVideoUpload(
    <?php echo $result; ?>,
    '<?php echo "<input name='vidid' type='text' value='".$id."'/>" . $_FILES['fileVideo']['name']; ?>'
  );
</script>

The error I am recieving is: syntaxError: missing ) after argument list.

Upvotes: 0

Views: 96

Answers (2)

mplungjan
mplungjan

Reputation: 178285

Escape your quotes

<script language="javascript" type="text/javascript">
  window.top.stopVideoUpload(
    <?php echo $result; ?>,
    '<?php echo "<input name=\'vidid\' type=\'text\' value=\'".$id."\'/>" . $_FILES['fileVideo']['name']; ?>'
  );
</script>

depending on what $result is - should be a number or it must be quoted too We also need to know what $_FILES contains so please post the rendered view-source of what you have now

The escaping should make it look like

  window.top.stopVideoUpload(
    10,
    '<input name=\'vidid\' type=\'text\' value=\'someId'/> bla'
  );

This is easier to read

 '<?php echo '<input name="vidid" type="text" value="'.$id.'" />' . $_FILES['fileVideo']['name']; ?>'

which gives

  window.top.stopVideoUpload(
    10,
    '<input name="vidid" type="text" value="someId"/> bla'
  );

Upvotes: 2

Ja͢ck
Ja͢ck

Reputation: 173642

Always escape your outputs:

window.top.stopVideoUpload(
    <?php echo json_encode($result); ?>,
    <?php echo json_encode("<input name='vidid' type='text' value='".$id."'/>" . $_FILES['fileVideo']['name']); ?>
);

In this case, you're outputting values that should be used in JavaScript, so use json_encode() to write valid JavaScript values.

Upvotes: 0

Related Questions