473,656 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DOM javascript working fine with IE but nothing happens with Firefox

Hello everyone, I have this javascript code working perfectly with IE,
but with firefox nothing happens when running the function...

function add_div_field () {

var ni = document.getEle mentById('uploa d_div');
var num = contador_upload ++;
var div = document.create Element("div");
var div_name = "filediv"+n um;
div.setAttribut e("id",div_name );

var table1 = document.create Element("<table width='100%'
class='table0' border='0'>");

var tbody1 = document.create Element("tbody" );

var tr1 = document.create Element("<tr width='100%'
id='upload_tabl e"+num+"'>") ;
var td1 = document.create Element("<td width='13'>");
var strong1 = document.create Element("strong ");
var txtno = document.create TextNode(num+'. ');

strong1.appendC hild(txtno);

td1.appendChild (strong1);

var td2 = document.create Element("<td width='700' valign='middle'
class='grey_sma ll'>");
var div2 = document.create Element("<div id='file"+num+" '
class='showme'> ");
var iframe = document.create Element("<ifram e align='middle'
marginheight='0 ' scrolling='no' marginwidth='0' frameborder='0'
width='300' height='22' src='upload2.ph p?upload_id="+n um+"'>");
div2.appendChil d(iframe);

var div3 = document.create Element("<div id='waiting"+nu m+"'
class='hideme'> ");
var txtwaiting = document.create TextNode(' Subiendo imagen, espera
unos instantes...');
var br = document.create Element("br");

var imgwaiting = document.create Element('<img src="pics/
uploading.gif" width="220" height="19" align="absmiddl e">');
div3.appendChil d(txtwaiting);
div3.appendChil d(br);
div3.appendChil d(imgwaiting);

var div4 = document.create Element("<div id='end_upload" +num+"'
class='hideme'> ");
var table2 = document.create Element("<table width='100%'>") ;

var tbody2 = document.create Element("tbody" );

var tr2 = document.create Element("tr");

var td3 = document.create Element("<td height='10'>");

tr2.appendChild (td3);

var tr3 = document.create Element("tr");
var td4 = document.create Element("td");
var txttitle = document.create TextNode("Títul o:");

td4.appendChild (txttitle);
tr3.appendChild (td4);

var tr4 = document.create Element("tr");
var td5 = document.create Element("td");

var inputTitle = document.create Element("<input type='text'
name='title["+num+"]' id='title["+num+"]'>");
var inputTitleName = "title["+num+"]";

td5.appendChild (inputTitle);
tr4.appendChild (td5);

var tr5 = document.create Element("tr");
var td6 = document.create Element("td");

var txtdesc = document.create TextNode("Descr ipción Opcional:");

td6.appendChild (txtdesc);
tr5.appendChild (td6);

var tr6 = document.create Element("tr");
var td7 = document.create Element("td");

var inputDesc = document.create Element("<texta rea id='desc["+num+"]'
name='desc["+num+"]' cols='40' rows='4'>");
var inputDescName = "desc["+num+"]";

td7.appendChild (inputDesc);
tr6.appendChild (td7);

var tr7 = document.create Element("tr");
var td8 = document.create Element("<td height='10'>");

tr7.appendChild (td8);

tbody2.appendCh ild(tr2);
tbody2.appendCh ild(tr3);
tbody2.appendCh ild(tr4);
tbody2.appendCh ild(tr5);
tbody2.appendCh ild(tr6);
tbody2.appendCh ild(tr7);

table2.appendCh ild(tbody2);

div4.appendChil d(table2);

td2.appendChild (div2);
td2.appendChild (div3);
td2.appendChild (div4);

var td9 = document.create Element("<td width='21'>");

var txtempty = document.create TextNode(" ");

td9.appendChild (txtempty);

var td10 = document.create Element("<td width='189'>");

var imgphoto = document.create Element("<img src='pics/blank50x50.gif'
id='photo"+num+ "' name='photo"+nu m+"' width='50' height='50'
class='upload_b order'>");

td10.appendChil d(imgphoto);

tr1.appendChild (td1);
tr1.appendChild (td2);
tr1.appendChild (td10);

tbody1.appendCh ild(tr1);

table1.appendCh ild(tbody1);

div.appendChild (table1);

ni.appendChild( div);

}

Thank you!

May 17 '07 #1
6 1971
ApOG wrote:
var table1 = document.create Element("<table width='100%'
class='table0' border='0'>");
var tr1 = document.create Element("<tr width='100%'
id='upload_tabl e"+num+"'>") ;
var td1 = document.create Element("<td width='13'>");
With the W3C DOM the createElement method takes a string with the tag
name of the element. Passing in a complete start tag with attributes is
not supported, that is something that IE/Win supports but other
implementations do not support.
--

Martin Honnen
http://JavaScript.FAQTs.com/
May 17 '07 #2

ApOG wrote:
Hello everyone, I have this javascript code working perfectly with IE,
but with firefox nothing happens when running the function...

function add_div_field () {

var ni = document.getEle mentById('uploa d_div');
var num = contador_upload ++;
var div = document.create Element("div");
var div_name = "filediv"+n um;
div.setAttribut e("id",div_name );

var table1 = document.create Element("<table width='100%'
class='table0' border='0'>");
----8<---snipped--8<------

see the difference in createElement between firefox and IE.
http://developer.mozilla.org/en/docs....createElement
http://msdn2.microsoft.com/en-us/library/ms536389.aspx

the usual advice is steer clear of the microsoft website when learning
new methods

Instead use
http://developer.mozilla.org and
http://www.w3.org
then once your code works in standards based browsers, hack the code
(if needed) to work in M$ IE6+
IMHO You were using functionality helpfully provided by M$ and
unsupported by any known standard.

May 17 '07 #3
On May 17, 3:56 am, ApOG <feinh...@viber agency.comwrote :
Hello everyone, I have this javascript code working perfectly with IE,
but with firefox nothing happens when running the function...

function add_div_field () {

var ni = document.getEle mentById('uploa d_div');
var num = contador_upload ++;
var div = document.create Element("div");
var div_name = "filediv"+n um;
div.setAttribut e("id",div_name );

var table1 = document.create Element("<table width='100%'
class='table0' border='0'>");
--------snipped-------
apologies if this post appears twice.

You are another victim of msdn I am afraid, you are using M$
proprietary features of createElement.

Rule number 1: stay away from micro$oft website when learning new
methods.
Instead use
http://developer.mozilla.org/
in particular this link
http://developer.mozilla.org/en/docs....createElement

and
http://www.w3.org/
in particular these pages
http://www.w3.org/TR/DOM-Level-2-Core/core.html
http://www.w3.org/TR/DOM-Level-3-Core/core.html

since you cannot rely on microsoft methods to be compliant with
standards, you should code first for firefox and other browsers which
attempt a stab at standards, and hack your code to work in IE if it
doesn't already.

May 17 '07 #4
On May 17, 3:56 am, ApOG <feinh...@viber agency.comwrote :
Hello everyone, I have this javascript code working perfectly with IE,
but with firefox nothing happens when running the function...

function add_div_field () {

var ni = document.getEle mentById('uploa d_div');
var num = contador_upload ++;
var div = document.create Element("div");
var div_name = "filediv"+n um;
div.setAttribut e("id",div_name );

var table1 = document.create Element("<table width='100%'
class='table0' border='0'>");

var tbody1 = document.create Element("tbody" );

var tr1 = document.create Element("<tr width='100%'
id='upload_tabl e"+num+"'>") ;

var td1 = document.create Element("<td width='13'>");

var strong1 = document.create Element("strong ");
var txtno = document.create TextNode(num+'. ');

strong1.appendC hild(txtno);

td1.appendChild (strong1);

var td2 = document.create Element("<td width='700' valign='middle'
class='grey_sma ll'>");

var div2 = document.create Element("<div id='file"+num+" '
class='showme'> ");

var iframe = document.create Element("<ifram e align='middle'
marginheight='0 ' scrolling='no' marginwidth='0' frameborder='0'
width='300' height='22' src='upload2.ph p?upload_id="+n um+"'>");

div2.appendChil d(iframe);

var div3 = document.create Element("<div id='waiting"+nu m+"'
class='hideme'> ");

var txtwaiting = document.create TextNode(' Subiendo imagen, espera
unos instantes...');
var br = document.create Element("br");

var imgwaiting = document.create Element('<img src="pics/
uploading.gif" width="220" height="19" align="absmiddl e">');

div3.appendChil d(txtwaiting);
div3.appendChil d(br);
div3.appendChil d(imgwaiting);

var div4 = document.create Element("<div id='end_upload" +num+"'
class='hideme'> ");

var table2 = document.create Element("<table width='100%'>") ;

var tbody2 = document.create Element("tbody" );

var tr2 = document.create Element("tr");

var td3 = document.create Element("<td height='10'>");

tr2.appendChild (td3);

var tr3 = document.create Element("tr");
var td4 = document.create Element("td");
var txttitle = document.create TextNode("Títul o:");

td4.appendChild (txttitle);
tr3.appendChild (td4);

var tr4 = document.create Element("tr");
var td5 = document.create Element("td");

var inputTitle = document.create Element("<input type='text'
name='title["+num+"]' id='title["+num+"]'>");
var inputTitleName = "title["+num+"]";

td5.appendChild (inputTitle);
tr4.appendChild (td5);

var tr5 = document.create Element("tr");
var td6 = document.create Element("td");

var txtdesc = document.create TextNode("Descr ipción Opcional:");

td6.appendChild (txtdesc);
tr5.appendChild (td6);

var tr6 = document.create Element("tr");
var td7 = document.create Element("td");

var inputDesc = document.create Element("<texta rea id='desc["+num+"]'
name='desc["+num+"]' cols='40' rows='4'>");
var inputDescName = "desc["+num+"]";

td7.appendChild (inputDesc);
tr6.appendChild (td7);

var tr7 = document.create Element("tr");
var td8 = document.create Element("<td height='10'>");

tr7.appendChild (td8);

tbody2.appendCh ild(tr2);
tbody2.appendCh ild(tr3);
tbody2.appendCh ild(tr4);
tbody2.appendCh ild(tr5);
tbody2.appendCh ild(tr6);
tbody2.appendCh ild(tr7);

table2.appendCh ild(tbody2);

div4.appendChil d(table2);

td2.appendChild (div2);
td2.appendChild (div3);
td2.appendChild (div4);

var td9 = document.create Element("<td width='21'>");

var txtempty = document.create TextNode(" ");

td9.appendChild (txtempty);

var td10 = document.create Element("<td width='189'>");

var imgphoto = document.create Element("<img src='pics/blank50x50.gif'
id='photo"+num+ "' name='photo"+nu m+"' width='50' height='50'
class='upload_b order'>");

td10.appendChil d(imgphoto);

tr1.appendChild (td1);
tr1.appendChild (td2);
tr1.appendChild (td10);

tbody1.appendCh ild(tr1);

table1.appendCh ild(tbody1);

div.appendChild (table1);

ni.appendChild( div);

}

Thank you!


***nb: google groups is playing up again - this is so boring, I
apologise if there end up being 3 posts or something:
--------snipped-------
apologies if this post appears twice.

You are another victim of msdn I am afraid, you are using M$
proprietary features of createElement.

Rule number 1: stay away from micro$oft website when learning new
methods.
Instead use
http://developer.mozilla.org/
in particular this link
http://developer.mozilla.org/en/docs....createElement

and
http://www.w3.org/
in particular these pages
http://www.w3.org/TR/DOM-Level-2-Core/core.html
http://www.w3.org/TR/DOM-Level-3-Core/core.html

since you cannot rely on microsoft methods to be compliant with
standards, you should code first for firefox and other browsers which
attempt a stab at standards, and hack your code to work in IE if it
doesn't already.

May 17 '07 #5
On May 16, 10:56 pm, ApOG <feinh...@viber agency.comwrote :
Hello everyone, I have this javascript code working perfectly with IE,
but with firefox nothing happens when running the function...

function add_div_field () {

var ni = document.getEle mentById('uploa d_div');
var num = contador_upload ++;
var div = document.create Element("div");
var div_name = "filediv"+n um;
div.setAttribut e("id",div_name );

var table1 = document.create Element("<table width='100%'
class='table0' border='0'>");

var tbody1 = document.create Element("tbody" );

var tr1 = document.create Element("<tr width='100%'
id='upload_tabl e"+num+"'>") ;

var td1 = document.create Element("<td width='13'>");

var strong1 = document.create Element("strong ");
var txtno = document.create TextNode(num+'. ');

strong1.appendC hild(txtno);

td1.appendChild (strong1);

var td2 = document.create Element("<td width='700' valign='middle'
class='grey_sma ll'>");

var div2 = document.create Element("<div id='file"+num+" '
class='showme'> ");

var iframe = document.create Element("<ifram e align='middle'
marginheight='0 ' scrolling='no' marginwidth='0' frameborder='0'
width='300' height='22' src='upload2.ph p?upload_id="+n um+"'>");

div2.appendChil d(iframe);

var div3 = document.create Element("<div id='waiting"+nu m+"'
class='hideme'> ");

var txtwaiting = document.create TextNode(' Subiendo imagen, espera
unos instantes...');
var br = document.create Element("br");

var imgwaiting = document.create Element('<img src="pics/
uploading.gif" width="220" height="19" align="absmiddl e">');

div3.appendChil d(txtwaiting);
div3.appendChil d(br);
div3.appendChil d(imgwaiting);

var div4 = document.create Element("<div id='end_upload" +num+"'
class='hideme'> ");

var table2 = document.create Element("<table width='100%'>") ;

var tbody2 = document.create Element("tbody" );

var tr2 = document.create Element("tr");

var td3 = document.create Element("<td height='10'>");

tr2.appendChild (td3);

var tr3 = document.create Element("tr");
var td4 = document.create Element("td");
var txttitle = document.create TextNode("Títul o:");

td4.appendChild (txttitle);
tr3.appendChild (td4);

var tr4 = document.create Element("tr");
var td5 = document.create Element("td");

var inputTitle = document.create Element("<input type='text'
name='title["+num+"]' id='title["+num+"]'>");
var inputTitleName = "title["+num+"]";

td5.appendChild (inputTitle);
tr4.appendChild (td5);

var tr5 = document.create Element("tr");
var td6 = document.create Element("td");

var txtdesc = document.create TextNode("Descr ipción Opcional:");

td6.appendChild (txtdesc);
tr5.appendChild (td6);

var tr6 = document.create Element("tr");
var td7 = document.create Element("td");

var inputDesc = document.create Element("<texta rea id='desc["+num+"]'
name='desc["+num+"]' cols='40' rows='4'>");
var inputDescName = "desc["+num+"]";

td7.appendChild (inputDesc);
tr6.appendChild (td7);

var tr7 = document.create Element("tr");
var td8 = document.create Element("<td height='10'>");

tr7.appendChild (td8);

tbody2.appendCh ild(tr2);
tbody2.appendCh ild(tr3);
tbody2.appendCh ild(tr4);
tbody2.appendCh ild(tr5);
tbody2.appendCh ild(tr6);
tbody2.appendCh ild(tr7);

table2.appendCh ild(tbody2);

div4.appendChil d(table2);

td2.appendChild (div2);
td2.appendChild (div3);
td2.appendChild (div4);

var td9 = document.create Element("<td width='21'>");

var txtempty = document.create TextNode(" ");

td9.appendChild (txtempty);

var td10 = document.create Element("<td width='189'>");

var imgphoto = document.create Element("<img src='pics/blank50x50.gif'
id='photo"+num+ "' name='photo"+nu m+"' width='50' height='50'
class='upload_b order'>");

td10.appendChil d(imgphoto);

tr1.appendChild (td1);
tr1.appendChild (td2);
tr1.appendChild (td10);

tbody1.appendCh ild(tr1);

table1.appendCh ild(tbody1);

div.appendChild (table1);

ni.appendChild( div);

}

Thank you!
Try using this technique instead:

function start() {
// get the reference for the body
var body = document.getEle mentsByTagName( "body")[0];

// creates a <tableelement and a <tbodyelement
var tbl = document.create Element("table" );
var tblBody = document.create Element("tbody" );

// creating all cells
for (var j = 0; j < 2; j++) {
// creates a table row
var row = document.create Element("tr");

for (var i = 0; i < 2; i++) {
// Create a <tdelement and a text node, make the
text
// node the contents of the <td>, and put the <tdat
// the end of the table row
var cell = document.create Element("td");
var cellText = document.create TextNode("cell is row "+j
+", column "+i);
cell.appendChil d(cellText);
row.appendChild (cell);
}

// add the row to the end of the table body
tblBody.appendC hild(row);
}

// put the <tbodyin the <table>
tbl.appendChild (tblBody);
// appends <tableinto <body>
body.appendChil d(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribut e("border", "2");
}

This must be the problem in Firefox: document.create Element("<td
width='21'>");

--
VUNET
www.worldincatalog.com

May 17 '07 #6
On May 17, 12:56 pm, ApOG <feinh...@viber agency.comwrote :
Hello everyone, I have this javascript code working perfectly with IE,
but with firefox nothing happens when running the function...

function add_div_field () {

var ni = document.getEle mentById('uploa d_div');
var num = contador_upload ++;
Where is contador_upload defined?

var div = document.create Element("div");
var div_name = "filediv"+n um;
div.setAttribut e("id",div_name );
setAttribute is problematic in some browsers, just set the property
directly:

div.id = div_name;

var table1 = document.create Element("<table width='100%'
class='table0' border='0'>");
The argument to createElement is supposed to be a tag name, not a
string of HTML.

<URL: http://www.w3.org/TR/DOM-Level-2-Cor...#ID-2141741547 >

var tbody1 = document.create Element("tbody" );

var tr1 = document.create Element("<tr width='100%'
id='upload_tabl e"+num+"'>") ;
You can create the table with:

var table = document.create Element('table' );

then skip the tbody and just insert rows into the table:

var row = table.insertRow (-1);

>
var td1 = document.create Element("<td width='13'>");
var cell = row.insertCell(-1);

and so on. There's an example here:

<URL: http://developer.mozilla.org/en/docs...able_Interface
>

There are likely many more things to fix - you should look for
patterns in your code and run some loops or clones to reduce all those
lines of near identical code.
--
Rob

May 17 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3108
by: maxfloden | last post by:
I have added a Button control (also tried LinkButton with same result) and some code to the click event to my web form in vb.net/vs.net. When I test it from a browser (IE6) the button shows up but when I click it nothing happens. In the IE status bar it says "javascript:{if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) __doPostBack('btnTest','')}" but absolutely nothing happens when I click it. There seems to be...
0
1717
by: mark | last post by:
Hello, I have an Access 2000 database with a hyperlink field. The field stores links to .jpg files stored on my hard disk. *When I click on the link, nothing happens!!* When I create a link to any other kind of file (eg. PDF), the link works fine. This has worked fine in the past, though I did convert from Access 97 to 2000 at one point (not sure if this is when the problem started). I have checked and rechecked proper syntax. I...
7
9599
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script language="JavaScript"> var cntlName; var eleTarget = document.getElementById('hiding'); function showOrHide(){
1
1253
by: puginews | last post by:
Hi, I have a webpage with a dropdownlist on it. I fill the dropdownlist with data from database. This works fine. Now I want to create an onchange event (selectedindexchanged), I doubleclick on the dropdownlist and write the code. Nothing happens on the webpage when I choose another item (option). The event never occurs. When I use a button and I copy paste the code there, it works using the button. Why doesn't the selectedIndexChanged...
11
3426
by: minnesotti | last post by:
Hi there, I subscribed to a photographic pictures-hosting website which is heavy on JavaScript. My preferred latest browser Mozilla Firefox does not work with it -- no pictures are displayed and no buttons react to clicking. The website's helpdesk says it should work with Firefox, and could not offer any more advices. The JavaScript Console shows that there are numerous errors occuring. It looks like the web browser does not recognise...
2
1539
by: fedorpawel | last post by:
I want to redirect the user to the current month such as November2006.html, but only if the month exists in pubMon array. This code works correctely in IE but stopped working in the new Firefox. In Firefox it always redirects to the default Annoucments.html. What am I missing? Thanks for any help. /////Returns true if the val is an element of the array a function find(a, val){
1
1827
by: web20tester | last post by:
Hi all, I am new to javascript. I have this script working fine in IE but cannot work in firefox. Really appreciate on any guidance. search0.js function Search(str) { var textD=parent.textFrame.document; var SearchRange = textD.body.createTextRange();
14
7185
by: sourav08 | last post by:
Hi, I have validate a text field with onchange event which throw error message, if not satisfied the condition and set the mouse cursor on the same field using document.focus(). It is working fine in IE, but when used in Firefox, the mouse cursor is moving to the next text field. Please let me know the possible solution for the above problem.
2
3049
by: sateeshchandrasanga | last post by:
Hi All, My HTML code is working fine in Firefox.But its not displaying any thing in IE.Can you help me in this problem.And in Google crown its displaying but not properly. contactus.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.