473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

JS is working in firefox but not working in IE

Hi All,

i am using this below addElement() function to create the file element dynamically

Expand|Select|Wrap|Line Numbers
  1. function addElement( filename,businessName ){
  2.  
  3. // Make sure it's a file input element
  4. //if( element.tagName == 'INPUT' && element.type == 'file' )
  5. {
  6. var textdiv = document.createTextNode('SER file to upload:'); 
  7. var new_element = document.createElement( 'input' );
  8. var divdetails =document.createElement('div');
  9. divdetails.id='files_div'+filecount
  10.  
  11. new_element.type = 'file';
  12. new_element.id='my_file_element'+filecount;
  13.  
  14.  new_element.setAttribute('name','testFile[' +  filecount  +  ']'); 
  15.  
  16. var treval = 'document.getElementById("files_div'+filecount+'").style.display="block"'; 
  17. var treval1 = 'document.getElementById("files_div'+filecount+'").style.position="absolute"'; 
  18. var treval2 = 'document.getElementById("files_div'+filecount+'").style.top="78px"'; 
  19.  
  20. filecount++
  21. var tableid = document.getElementById('tableid');
  22.  
  23. divdetails.appendChild(textdiv); 
  24.  
  25. divdetails.appendChild(new_element);
  26. tableid.appendChild(divdetails);
  27. //document.upload.appendChild(divdetails);
  28. document.upload.appendChild(new_hiddenelement);
  29. //document.getElementById("tempFiles").style.display="none";
  30. if(document.getElementById("files_div0") !=null)
  31. {
  32. document.getElementById("files_div0").style.visibility="hidden";
  33. }
  34. eval(treval);
  35. eval(treval1);
  36. eval(treval2);
  37.  
  38. };
  39.  
and using this below codei am retriving the value of dyamically created file

Expand|Select|Wrap|Line Numbers
  1. value_of_file = 'document.upload.elements["testFile[' +  count_list1 +  ']"].value'                
  2. value_of_file = eval(value_of_file);
  3.  
above code is working perfectly in teh firefox but in IE it was showing null value exception


please help to solve this problem..


thanks in advance....


Riaz
Oct 24 '08 #1
5 1733
acoder
16,027 Expert Mod 8TB
Unfortunately, IE doesn't set the names of elements with setAttribute() or .name syntax when created dynamically. It needs its own non-standard syntax in createElement(). You may find this link useful for a cross-browser solution.
Oct 24 '08 #2
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. var pinput = document.createElement("INPUT");
  2. pinput.setAttribute("id", "partnum");
  3. pinput.setAttribute("name", "partnum");
  4. pinput.id="partnum";
  5. pinput.name="partnum";
  6.  
This is some code I use for setting the names of created Elements without the IE hack... this seems to work in all browsers i've tested on.. ie6, ie7, firefox, google chrome.. It doesn't seem to work if the id attribute is not there.. If i remember correctly it doesn't seem to work if the id attribute isn't there first.

Now here comes the part that gets people confused and think that .name doesn't work.. IE only gets elements by name if they are native form elements... input, select, textarea so on

So I use this
Expand|Select|Wrap|Line Numbers
  1. function getAllElementsByName(name) {
  2.     var Elements=document.getElementsByTagName("*");
  3.     var Return_Array=Array();
  4.     var r=0;
  5.     for (var i=0; i<Elements.length; i++) {
  6.         if (Elements[i].getAttribute("name")==name) {
  7.             Return_Array[r]=Elements[i];
  8.             r++;
  9.         }
  10.     }
  11.     return Return_Array;
  12. }
  13.  
Oct 24 '08 #3
correct me if I'm wrong clint, but IE doesn't allow setting the name attribute for grouped input items (like radio and check boxes) after creation, (or dynamically in 6 period) I've had to use the very irritating

Expand|Select|Wrap|Line Numbers
  1. document.createElement("<input type="+args.type+" name="args.name">")
method...

As far as I know, if you dynamically create form elements, there are some wierd caveats that ie refuses to make easier.

also why:

Expand|Select|Wrap|Line Numbers
  1.   var r=0;
  2.   for (var i=0; i<Elements.length; i++) {
  3.      if (Elements[i].getAttribute("name")==name) {
  4.         Return_Array[r]=Elements[i];
  5.         r++;
  6.   }
in that scenario don't 'i' and 'r' equal the same value?
Oct 24 '08 #4
iam_clint
1,208 Expert 1GB
r won't always be the same because i is incrementing with no if statements
r only increments when Elements[i].getAttribute("name")==name
Expand|Select|Wrap|Line Numbers
  1.   var r=0; 
  2.   for (var i=0; i<Elements.length; i++) { 
  3.      if (Elements[i].getAttribute("name")==name) { 
  4.         Return_Array[r]=Elements[i]; 
  5.         r++; 
  6.      }
  7.   } 
  8.  
as to the other question i'm not sure off the top of my head I would have to run some tests.
Oct 24 '08 #5
sorry, should have read the code more thoroughly:p
Oct 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gregory Piñero | last post by:
Hi guys, I'm trying to run this statement: os.system(r'"C:\Program Files\Mozilla Firefox\firefox.exe"' + ' "www.blendedtechnologies.com"') The goal is to have firefox open to that website....
3
by: The Bicycling Guitarist | last post by:
http://www.TheBicyclingGuitarist.net/css/index.css I have red nav buttons that turn blue when hovered over and turn purple after being visited. The red and blue work in FireFox, but not the visited...
3
by: TJS | last post by:
I am finding that the serverside requiredvalidator doesn't fire in the firefox browser, and user request proceeds through to my updateProfile method. Validation is working correctly in the IE...
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
49
by: Atul Chaturvedi | last post by:
If we use ASP.NET 2.0 Login Control, we are unable to click on Login and Reset Buttons on Safari running on Apple Mac OS X Version 10.3.2 . How can i resolve the problem.
2
by: Velvet | last post by:
I'm using the standard upload component in ASP.NET 1.1 to allow authors to upload manuscripts to our server. This is working fine except for some people using FireFox. The problem is, the...
3
by: Snt | last post by:
Hi! I am trying to get AJAX working on multiple browsers and am having a problem with Firefox. I have the following code: function handleState3(){ switch(http.readyState) { case 0: //...
6
by: Toby Inkster | last post by:
Does anyone have any idea why this effect using script.aculo.us is working in Opera, but not Firefox? http://examples.tobyinkster.co.uk/Balloons2/Balloon%20tooltip.html (I've not had the...
1
by: Sura | last post by:
Hi I have a flash interactive window which has html links and this appears on an html page. This window can be moved with the mouse on the html page. The html page has an iFrame too. When the...
2
by: willyWEB66 | last post by:
Hi everyone, I have this code in javascript where the XML file is loaded and displayed to an html using XSLT. It works fine in IE but not in Firefox. My problem is in the looping to the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.