| | |
.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 |
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)
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
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
**JS function called Contact** var loadingImg = document.createElement("img"); loadingImg.setAttribute("src", "/images/contact-playing.jpg"); loadingImg.setAttribute("width", "492"); loadingImg.setAttribute("height", "153"); loadingImg.setAttribute("alt", "Playing In My Studio"); document.getElementById("ContactFormDiv").insertBefore(loadingImg, ContactForm);
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
**HTML** <div id="ContactFormDiv"> <p id="hope">Test</p> <form action="javascript:Contact();" method="post" name="ContactForm" id="ContactForm"> <input name="name" id="name" type="text" maxlength="50" tabindex="1" value="" /> <input name="email" id="email" type="text" maxlength="50" tabindex="2" value="" /> <textarea name="comments" id="comments" cols="50" rows="10" tabindex="3"></textarea> <input type="hidden" name="frmVid" id="frmVid" value="<?php echo $frmVid;?>" /> <input type="hidden" name="frmTitle" id="frmTitle" value="<?php echo $frmTitle;?>" /> <input class="submit" type="submit" name="submit" value="Submit" tabindex="4" /> </form> </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
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
> document.getElementById("ContactFormDiv").insertBefore(loadingImg, 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
•
•
•
•
Where have you defined ContactForm?JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
> document.getElementById("ContactFormDiv").insertBefore(loadingImg, ContactForm);
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
Then it won't work since
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)
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)
var myDiv = document.getElementById("ContactFormDiv"); var myFrm = document.forms["ContactForm"]; myDiv.insertBefore(loadingImg, myFrm);
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
•
•
•
•
Then it won't work sinceinsertBeforeexpects 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:
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)JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var myDiv = document.getElementById("ContactFormDiv"); var myFrm = document.forms["ContactForm"]; myDiv.insertBefore(loadingImg, myFrm);
Anthony
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
![]() |
Similar Threads
- javascript works in IE but not working in firefox (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: browser compatability
- Next Thread: Firefox message bar with JS
Views: 2841 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp ajaxjspservlets animate api automatically blackjack browser bug calendar captchaformproblem checkbox child class close cookies createrange() cursor dependent disablefirebug dom dropdown editor element engine events explorer ext file firehose flash form forms game google gxt hiddenvalue highlightedword html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump libcurl margin math matrixcaptcha media microsoft mp3 mysql object offline onmouseoutdivproblem onreadystatechange parent passing pdf php player post progressbar rated regex runtime scroll search security session shopping size software solutions sql star stars stretch synchronous text textarea twitter unicode validation web website window windowsxp wysiwyg xspf \n






