Works in IE not Firefox

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: 6
Reputation: adino2 is an unknown quantity at this point 
Solved Threads: 0
adino2 adino2 is offline Offline
Newbie Poster

Works in IE not Firefox

 
0
  #1
Sep 21st, 2009
I written a code to create a image viewer using javascript. But the script only works in IE but not in firefox. Please help.

The code is below......

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2.  
  3. function changeImage(filename)
  4. {
  5. mainimage.src = filename;
  6. }
  7.  
  8. </script>
  9. <center>
  10.  
  11. <img src="images/bg.jpg" name="mainimage" width="419" height="282">
  12. <marquee width="90%" scrollamount="5" onmouseover="this.stop();" onmouseout="this.start();">
  13.  
  14. <?php
  15. include 'database_conn.php';
  16. $tbl_name="property";
  17.  
  18. $sql = "SELECT * FROM $tbl_name WHERE worth='1' && activation='1'";
  19. $query = mysql_query($sql) or die(mysql_error());
  20. echo "<table><tr>";
  21.  
  22. while ($row =mysql_fetch_array($query))
  23. {
  24. $title = $row['title'];
  25. $area = $row['area'];
  26. $propertyid = $row['propertyid'];
  27. $image1 = $row['image1'];
  28. $contact = $row['contact'];
  29. $price = $row['price'];
  30.  
  31. if (empty($image1))
  32. {
  33. $image1 = "uploaded_files/no photo.jpg";
  34. ?><a href="javascript:changeImage('<?php echo $image1;?>')"><td><center><?php echo "$title";?></center><img src="<?php echo $image1;?>" width='90' height='80'><br><center><a href='detail.php?propertyid=<?php echo "$propertyid'"; ?>'>Details</a></center></td><?php
  35. }
  36. else
  37. {
  38. ?><a href="javascript:changeImage('<?php echo $image1;?>')"><td><center><?php echo "$title";?></center><img src="<?php echo $image1;?>" width='90' height='80'><br><center><a href='detail.php?propertyid=<?php echo "$propertyid'"; ?>'>Details</a></center></td><?php
  39. }
  40. }
  41. echo "</tr></table>";
  42. mysql_close($conn);
  43.  
  44. ?></marquee></center>
  45. Reply With Quote
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 2
Reputation: matthewmaxwell is an unknown quantity at this point 
Solved Threads: 1
matthewmaxwell matthewmaxwell is offline Offline
Newbie Poster

Re: Works in IE not Firefox

 
0
  #2
Sep 21st, 2009
Originally Posted by adino2 View Post
I written a code to create a image viewer using javascript. But the script only works in IE but not in firefox. Please help.

The code is below......

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2.  
  3. function changeImage(filename)
  4. {
  5. mainimage.src = filename;
  6. }
  7.  
  8. </script>
  9. <center>
  10.  
  11. <img src="images/bg.jpg" name="mainimage" width="419" height="282">
  12. <marquee width="90%" scrollamount="5" onmouseover="this.stop();" onmouseout="this.start();">
You just need to change your function to:

function changeImage(filename)
{
document.getElementById("mainimage").src=filename;
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 348
Reputation: Troy III will become famous soon enough Troy III will become famous soon enough 
Solved Threads: 42
Troy III's Avatar
Troy III Troy III is offline Offline
Posting Whiz

Re: Works in IE not Firefox

 
0
  #3
Sep 21st, 2009
Originally Posted by adino2 View Post
I written a code to create a image viewer using javascript. But the script only works in IE but not in firefox. Please help.

The code is below......

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2.  
  3. function changeImage(filename)
  4. {
  5. mainimage.src = filename;
  6. }
  7.  
  8. </script>
  9. <center>
  10.  
  11. <img src="images/bg.jpg" name="mainimage" width="419" height="282">
  12. <marquee width="90%" scrollamount="5" onmouseover="this.stop();" onmouseout="this.start();">
  13.  
  14. <?php
  15. include 'database_conn.php';
  16. $tbl_name="property";
  17.  
  18. $sql = "SELECT * FROM $tbl_name WHERE worth='1' && activation='1'";
  19. $query = mysql_query($sql) or die(mysql_error());
  20. echo "<table><tr>";
  21.  
  22. while ($row =mysql_fetch_array($query))
  23. {
  24. $title = $row['title'];
  25. $area = $row['area'];
  26. $propertyid = $row['propertyid'];
  27. $image1 = $row['image1'];
  28. $contact = $row['contact'];
  29. $price = $row['price'];
  30.  
  31. if (empty($image1))
  32. {
  33. $image1 = "uploaded_files/no photo.jpg";
  34. ?><a href="javascript:changeImage('<?php echo $image1;?>')"><td><center><?php echo "$title";?></center><img src="<?php echo $image1;?>" width='90' height='80'><br><center><a href='detail.php?propertyid=<?php echo "$propertyid'"; ?>'>Details</a></center></td><?php
  35. }
  36. else
  37. {
  38. ?><a href="javascript:changeImage('<?php echo $image1;?>')"><td><center><?php echo "$title";?></center><img src="<?php echo $image1;?>" width='90' height='80'><br><center><a href='detail.php?propertyid=<?php echo "$propertyid'"; ?>'>Details</a></center></td><?php
  39. }
  40. }
  41. echo "</tr></table>";
  42. mysql_close($conn);
  43.  
  44. ?></marquee></center>
  45. Reply With Quote
Netscape UA children are not capable of recognizing DOM elements by their Names or IDs natively!
They'll need externally patched built-in functions attached to Document Object, to become aware of them and be able to reach them. But not without script action. They could trigger this function internally after onload event would fire, but that would impact their render engine, rise more memory issues present and would fail to update DOM changes on runtime because of internal ondomchange event imperfections that would occasionally rise errors like this or that element is "Undefined" even though present.and defined.

Therefore you will be needing a function call "document.getelementById() every time you have to reference some object to manipulate its properties. It's good to keep this in mind an not forget make that call whenever you are referencing to your aimed elements.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: adino2 is an unknown quantity at this point 
Solved Threads: 0
adino2 adino2 is offline Offline
Newbie Poster

Re: Works in IE not Firefox

 
0
  #4
Sep 21st, 2009
I tried using

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function changeImage(filename)
  2. {
  3. document.getElementById("mainimage").src=filename;
  4. }

It's not working in both IE and firefox
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 348
Reputation: Troy III will become famous soon enough Troy III will become famous soon enough 
Solved Threads: 42
Troy III's Avatar
Troy III Troy III is offline Offline
Posting Whiz

Re: Works in IE not Firefox

 
0
  #5
Sep 21st, 2009
Originally Posted by adino2 View Post
I tried using

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function changeImage(filename)
  2. {
  3. document.getElementById("mainimage").src=filename;
  4. }

It's not working in both IE and firefox
:')
"

DaniWeb Community > Web Development > JavaScript / DHTML / AJAX
JavaScript / DHTML / AJAX RSS JavaScript / DHTML / AJAX RSS
Works in IE not Firefox


:'p
Last edited by Troy III; Sep 21st, 2009 at 1:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: adino2 is an unknown quantity at this point 
Solved Threads: 0
adino2 adino2 is offline Offline
Newbie Poster

Re: Works in IE not Firefox

 
0
  #6
Sep 21st, 2009
Based on IE it says that Object doesn't support this method or property
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,389
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 168
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Works in IE not Firefox

 
0
  #7
Sep 21st, 2009
<img src="images/bg.jpg" name="mainimage" width="419" height="282"> Should be
  1. <img src="images/bg.jpg" id="mainimage" width="419" height="282">
and as previously written by mathewmaxwell
  1. function changeImage(filename)
  2. {
  3. document.getElementById("mainimage").src=filename;
  4. }
<element name= . is not formally deprecated, it just does not work
Last edited by almostbob; Sep 21st, 2009 at 1:37 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: adino2 is an unknown quantity at this point 
Solved Threads: 0
adino2 adino2 is offline Offline
Newbie Poster

Re: Works in IE not Firefox

 
0
  #8
Sep 21st, 2009
Aha, Thanks currently it works in IE again but still facing abit of problem in the Firefox , i'm guessing that there is some errors due to this part of codes.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="javascript:changeImage('<?php echo $image1;?>')"><td><center><?php echo "$title";?></center><img src="<?php echo $image1;?>" width='90' height='80'><br><center>
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: adino2 is an unknown quantity at this point 
Solved Threads: 0
adino2 adino2 is offline Offline
Newbie Poster

Re: Works in IE not Firefox

 
0
  #9
Sep 21st, 2009
I made a few changes

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. ?><td><center><a href="javascript:changeImage('<?php echo $image1;?>')"><?php echo "$title";?><br><img src="<?php echo $image1;?>" width='90' height='80'><br><a href='detail.php?propertyid=<?php echo "$propertyid'"; ?>'>Details</a></center></td><?php
  2.  

And finally it works

But mainly all thanks to the document.getElementById.

SOLVED
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,389
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 168
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Works in IE not Firefox

 
0
  #10
Sep 21st, 2009
extra suggestion is to get a code highlighting editor like notepad++ notepad2, or if the IDE you are using supports code highlighting turn it on
wrong code, missing quotes, too many quotes, unclosed pairs, out of sequence pairs will be highlighted
line 34 <a><td></a></td> shows as left in my editor will break






edit didn need the code to post too?
Last edited by almostbob; Sep 21st, 2009 at 2:03 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
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



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC