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>
asked Dec 20, 2015 at 19:27
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");
answered Dec 20, 2015 at 19:37
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");
answered Dec 20, 2015 at 19:36

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.

answered Dec 20, 2015 at 19:38

Comments

0

change First one with

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

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";
answered Dec 20, 2015 at 19:53

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");
answered Dec 20, 2015 at 20:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.