.insertBefore Not Working In FF

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

Join Date: May 2008
Posts: 110
Reputation: antwan1986 is an unknown quantity at this point 
Solved Threads: 8
antwan1986's Avatar
antwan1986 antwan1986 is offline Offline
Junior Poster

.insertBefore Not Working In FF

 
0
  #1
Jul 26th, 2008
Hi all and thanks for reading. I have a simple script that works in IE and Safari, but not FF. Basically when I click a button I want an image to appear dynamically via JS. This is what i've got (watered down)

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. **JS function called Contact**
  2.  
  3. var loadingImg = document.createElement("img");
  4. loadingImg.setAttribute("src", "/images/contact-playing.jpg");
  5. loadingImg.setAttribute("width", "492");
  6. loadingImg.setAttribute("height", "153");
  7. loadingImg.setAttribute("alt", "Playing In My Studio");
  8. document.getElementById("ContactFormDiv").insertBefore(loadingImg, ContactForm);

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. **HTML**
  2. <div id="ContactFormDiv">
  3. <p id="hope">Test</p>
  4. <form action="javascript:Contact();" method="post" name="ContactForm" id="ContactForm">
  5. <input name="name" id="name" type="text" maxlength="50" tabindex="1" value="" />
  6. <input name="email" id="email" type="text" maxlength="50" tabindex="2" value="" />
  7. <textarea name="comments" id="comments" cols="50" rows="10" tabindex="3"></textarea>
  8. <input type="hidden" name="frmVid" id="frmVid" value="<?php echo $frmVid;?>" />
  9. <input type="hidden" name="frmTitle" id="frmTitle" value="<?php echo $frmTitle;?>" />
  10. <input class="submit" type="submit" name="submit" value="Submit" tabindex="4" />
  11. </form>
  12. </div> <!-- Closes the ContactFormDiv div -->

So if i'm correct it should insert the image before the form with the id of contactform. it works in IE and safari but not FF, any ideas?

Thanks,

Anthony
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,653
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: .insertBefore Not Working In FF

 
0
  #2
Jul 27th, 2008
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. > document.getElementById("ContactFormDiv").insertBefore(loadingImg, ContactForm);
Where have you defined ContactForm?
The romantic image of an über-programmer is someone who fires up Emacs, types like a machine gun, and delivers a flawless final product from scratch. A more accurate image would be someone who stares quietly into space for a few minutes and then says “Hmm. I think I’ve seen something like this before.” - John D
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 110
Reputation: antwan1986 is an unknown quantity at this point 
Solved Threads: 8
antwan1986's Avatar
antwan1986 antwan1986 is offline Offline
Junior Poster

Re: .insertBefore Not Working In FF

 
0
  #3
Jul 27th, 2008
Originally Posted by ~s.o.s~ View Post
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. > document.getElementById("ContactFormDiv").insertBefore(loadingImg, ContactForm);
Where have you defined ContactForm?
Hi and thanks for your reply.

ContactForm is the name and ID of the Form.
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,653
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: .insertBefore Not Working In FF

 
0
  #4
Jul 27th, 2008
Then it won't work since insertBefore expects both arguments to be DOM element references. It works in IE since in IE the name of the element also contains the element reference. IMO, something like this should work:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var myDiv = document.getElementById("ContactFormDiv");
  2. var myFrm = document.forms["ContactForm"];
  3. myDiv.insertBefore(loadingImg, myFrm);
If it still doesn't work, look at the Error Console of Firefox which serves as a poor man's debugging utility. (Tools -> Error Console)
The romantic image of an über-programmer is someone who fires up Emacs, types like a machine gun, and delivers a flawless final product from scratch. A more accurate image would be someone who stares quietly into space for a few minutes and then says “Hmm. I think I’ve seen something like this before.” - John D
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 110
Reputation: antwan1986 is an unknown quantity at this point 
Solved Threads: 8
antwan1986's Avatar
antwan1986 antwan1986 is offline Offline
Junior Poster

Re: .insertBefore Not Working In FF

 
0
  #5
Jul 28th, 2008
Originally Posted by ~s.o.s~ View Post
Then it won't work since insertBefore expects both arguments to be DOM element references. It works in IE since in IE the name of the element also contains the element reference. IMO, something like this should work:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var myDiv = document.getElementById("ContactFormDiv");
  2. var myFrm = document.forms["ContactForm"];
  3. myDiv.insertBefore(loadingImg, myFrm);
If it still doesn't work, look at the Error Console of Firefox which serves as a poor man's debugging utility. (Tools -> Error Console)
Thanks very much for your help. I'll give that a try now and let you know how it went!

Anthony
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 110
Reputation: antwan1986 is an unknown quantity at this point 
Solved Threads: 8
antwan1986's Avatar
antwan1986 antwan1986 is offline Offline
Junior Poster

Re: .insertBefore Not Working In FF

 
0
  #6
Jul 28th, 2008
It works, thanks so so much for your help!

Anthony
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
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


Views: 2841 | Replies: 5
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