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>
-
What is it displaying in the HTML? See view source and tell how it is generating.Praveen Kumar Purushothaman– Praveen Kumar Purushothaman2015年12月20日 19:35:46 +00:00Commented Dec 20, 2015 at 19:35
-
Thanks for replies. I get those errors i can't click nothing!user1788736– user17887362015年12月20日 19:40:32 +00:00Commented Dec 20, 2015 at 19:40
6 Answers 6
Try this one:
echo ("<td><a href=\"javascript:loadVideo('$URL\','image1.jpg')\">".$item['name']."</a> <br/></td>\n");
Comments
Change the second one to:
echo ("<td><a onClick='loadVideo(\"" . $URL . "\");'>$item['name']</a><br/></td>\n");
Comments
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
change First one with
echo ("<td><a href=\"javascript:loadVideo(".$URL.",'image1.jpg')\">".$item['name']."</a> <br/></td>\n");
Comments
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
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");