I have dynamically generated (via php) a list of videos, each of which belongs to a different user with a profile picture ('userpic'). I am able to pass the 'userpic' to a javascript function 'video' called within the php as follows in this first echo statement:
<?php
//Lots of code
echo "<script>
function video(userpic) {
function AnotherFunction();
document.getElementById('UserPicHolder').innerHTML = userpic;
}
</script>";
//Lots of code
?>
Function 'video' calls AnotherFunction (works great). The path for var = userpic is the correct local path and displays correctly in the correct div ('UserPicHolder'). Everything works fine....then I change the inner HTML to an image attribute as follows:
<?php
//Lots of code
echo "<script>
function video(userpic) {
function AnotherFunction();
document.getElementById('UserPicHolder').innerHTML = '<img src=\"userpic\"
style=\"width:50px; height:55px\" alt=\"user picture\" class=\"SomeClass\"
title=\"Some text\">';
}
</script>";
//Lots of code
?>
In this second echo statement, even though the path is clearly correct as shown in the first echo statement, the image just does not display in 'UserPicHolder'. I have replaced userpic in the src with a local path and the icon displays correctly (in this third echo statement):
<?php
//Lots of code
echo "<script>
function video(userpic) {
function AnotherFunction();
document.getElementById('UserPicHolder').innerHTML = '<img src=\"images/icon.jpg\"
style=\"width:50px; height:55px\" alt=\"user picture\" class=\"SomeClass\"
title=\"Some text\">';
}
</script>";
//Lots of code
?>
Why is userpic in the second echo statement not being identifed in the inner HTML img src? Note I have also replaced (just guessing at this point after reading other posts) src=\"userpic\" with src=\"".userpic."\" and src=\""+userpic+"\" and src=\"+userpic+\" and src=\"".+userpic+."\" to no avail. Thanks for any help!
<?andphpon your code. I wonder how your code executes ? O.oUserPicHolderis sent before this javascript runs, right? Otherwise it won't exists anddocument.getElementById()will returnundefined.