0

Hi all i am trying to call javascript function called loadvideo from php echo and i keep getting errors. I tried two methods

1)first Method i get this error:

Parse error: syntax error, unexpected '<' in

echo ("<td><a href=\"javascript:loadVideo('$URL\','image1.jpg')">$item['name']</a> <br/></td>\n");

2)second method i get this error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

echo ("<td><a onClick='loadVideo(" . $URL . ");'>$item['name']</a><br/></td>\n");

could any one show me how to fix this ?Thanks in advance.

javascript function to call:

<script>
  function loadVideo(myFile,myImage) { 
    jwplayer().load([{
      file: myFile,
      image: myImage
    }]);
    jwplayer().play();
  };
</script>
2
  • What is it displaying in the HTML? See view source and tell how it is generating. Commented Dec 20, 2015 at 19:35
  • Thanks for replies. I get those errors i can't click nothing! Commented Dec 20, 2015 at 19:40

6 Answers 6

1

Try this one:

echo ("<td><a href=\"javascript:loadVideo('$URL\','image1.jpg')\">".$item['name']."</a> <br/></td>\n");
Sign up to request clarification or add additional context in comments.

Comments

0

Change the second one to:

echo ("<td><a onClick='loadVideo(\"" . $URL . "\");'>$item['name']</a><br/></td>\n");

Comments

0

I have check second method. There you missing quote of php variable.

Here is updated method

First method updated::

echo ("<td><a href=\"javascript:loadVideo('$URL','image1.jpg')\">$item['name']</a> <br/></td>\n");

Second method :

    echo ("<td><a onClick='loadVideo(" . $URL . ");'>".$item['name']."</a><br/></td>\n");

This will work.

Comments

0

change First one with

echo ("<td><a href=\"javascript:loadVideo(".$URL.",'image1.jpg')\">".$item['name']."</a> <br/></td>\n");

Comments

0

There are small bugs in your code.

Change the first one like this:

echo "<td><a href=\"javascript:loadVideo('$URL\','image1.jpg')\">{$item['name']}</a> <br/></td>\n";

And the second one like this:

echo "<td><a onClick='loadVideo(" . $URL . ");'>{$item['name']}</a><br/></td>\n";

Comments

0

First approach:

echo ("<td><a href=\"javascript:loadVideo('".$URL."','image1.jpg');\">".$item['name']."</a> <br/></td>\n");

Second approach:

echo ("<td><a onclick=\"loadVideo('".$URL."','image1.jpg');\">".$item['name']."</a> <br/></td>\n");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.