Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Dynamic ID

 
0
  #1
Nov 22nd, 2008
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

This is my javascript code
  1. <script type="text/javascript">
  2. function change_bg(id) {
  3. if(id != null && document.getElementById(id) != null) {
  4. document.getElementById(id+'bg').src='product_bg_big.png';
  5. document.getElementById(id+'fg').src='product_fg_big.png';
  6. document.getElementById(id).src='product_i_big.png';
  7. }
  8. else {
  9. confirm('');
  10. }
  11. }
  12.  
  13. function change_bg_back(id) {
  14. if(id != null && document.getElementById(id) != null) {
  15. document.getElementById(id+'bg').src='product_bg.png';
  16. document.getElementById(id+'fg').src='product_fg.png';
  17. document.getElementById(id).src='product_i.png';
  18. }
  19. else {
  20. confirm('');
  21. }
  22. }
  23. </script>

This is my php code:
  1. echo "<td>
  2. <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."')>
  3. </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
Last edited by brechtjah; Nov 22nd, 2008 at 5:26 pm. Reason: Forgot text
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Re: Dynamic ID

 
0
  #2
Nov 22nd, 2008
Solved it myself
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC