Hi,
I'm creating the layout for a dynamic webshop, all pictures are getting dynamic IDs to have their elements changed. I'm currently having errors with the code below and have no idea why.
the argument id is not null, however
document.getElementById(id) is. I don't understand how that can happen :S
This is my javascript code
<script type="text/javascript">
function change_bg(id) {
if(id != null && document.getElementById(id) != null) {
document.getElementById(id+'bg').src='product_bg_big.png';
document.getElementById(id+'fg').src='product_fg_big.png';
document.getElementById(id).src='product_i_big.png';
}
else {
confirm('');
}
}
function change_bg_back(id) {
if(id != null && document.getElementById(id) != null) {
document.getElementById(id+'bg').src='product_bg.png';
document.getElementById(id+'fg').src='product_fg.png';
document.getElementById(id).src='product_i.png';
}
else {
confirm('');
}
}
</script>
This is my php code:
echo "<td>
<img id='product".$numProduct."fg' src='product_fg.png' alt='product_fg' onmouseover=javascript:change_bg('product".$numProduct."') onmouseout=javascript:change_bg_back('product".$numProduct."')>
</td>";
EDIT: what's even stranger is that it all works, when I leave out the if, I just have a FireFox Addon which showed me those errors.
Any help would be very well appreciated.
Thanks