473,322 Members | 1,526 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,322 software developers and data experts.

IE7 does not create additional fields

105 100+
The code below adds a file field only if no other file field is empty.
The code works as expected in FF and Opera. However in IE7, it will only create one additional field.

Can anyone explain why IE7 refuses to create any more fields?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2.  
  3.     //initialises the container
  4.     function init() {
  5.  
  6.         container            =     document.getElementById('fieldset_images');
  7.  
  8.     }
  9.  
  10.     //checks if ANY childnode is empty
  11.     function empty(){
  12.  
  13.         var children     =     container.childNodes;
  14.         var count        =    children.length;
  15.  
  16.         for(var i =0; i <count; i++) {
  17.  
  18.             var childval    =    children[i].value;        
  19.             if (childval == "") return(true);
  20.         }
  21.  
  22.         return(false);
  23.  
  24.     }
  25.  
  26.  
  27.     //makes the field
  28.     function createField(){
  29.  
  30.         //checks if any fields are empty
  31.         if (empty()) return;
  32.  
  33.         input = document.createElement("input");
  34.         input.setAttribute("type", "file");
  35.         input.setAttribute("name", 'file[]');
  36.         input.setAttribute("onchange", 'createField();');
  37.  
  38.         container.appendChild(input);
  39.  
  40.     }
  41.  
  42.  
  43.     window.onload = init;
  44.  
  45.  
  46. </script>
  47.  
  48.  
  49. <fieldset id="fieldset_images"><input type="file" name="file[]" onchange="createField();" /></fieldset>
  50.  
  51.  
Jan 22 '09 #1
5 2153
acoder
16,027 Expert Mod 8TB
There's two problems. One which causes the problem you're having and the other which may cause you problems later.

The one which is the cause of the problem you mention is that IE will not set onchange via setAttribute. You have to set it directly:
Expand|Select|Wrap|Line Numbers
  1. input.onchange = createField;
The other bug is that IE does not set the names of dynamically created elements. I don't know if that is a problem in your case.
Jan 22 '09 #2
aktar
105 100+
Thanks for the insight ACODER. I have modified the code so that instead of creating an INPUT element, we create a DIV element. Then we just write the INPUT code in the innerHTML of the DIV element and append to child node array of the container element. That way we can solve the issue of IE7 not being able to set onChange attribute as well as the name attribute.

Thanks for your help

New code:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2.  
  3.     //makes the field
  4.     function createField(){
  5.  
  6.         var container    =     document.getElementById('fieldset_images');
  7.  
  8.         //checks if any fields are empty
  9.         var children     =     container.getElementsByTagName("input");
  10.         var count        =    children.length;
  11.  
  12.         for(var i =0; i <count; i++) {
  13.  
  14.             var childval    =    children[i].value;        
  15.             if (childval == "") return(false);
  16.         }        
  17.  
  18.  
  19.         //do the do do
  20.         var new_field        =    "<input type='file' name='file[]' onchange='createField();' />";
  21.  
  22.         input                 =     document.createElement("div");
  23.         input.innerHTML        =    new_field;
  24.  
  25.         container.appendChild(input);
  26.     }
  27.  
  28.  
  29.  
  30. </script>
  31.  
  32. <fieldset id="fieldset_images"><input type="file" name="file[]" onchange="createField();" /></fieldset>
Jan 22 '09 #3
acoder
16,027 Expert Mod 8TB
I suppose that's one way of doing it. Glad to see that you got it working.
Jan 22 '09 #4
Thanks acoder. Your suggestion solved my problem. Thanks for the same
adding the input.onchange = Add; solved my problem. Now it works both in IE and FF. Thanks a TON
Apr 2 '09 #5
acoder
16,027 Expert Mod 8TB
You're welcome, and welcome to Bytes!

That's a simple solution. You could also use addEventListener/attachEvent to add events.
Apr 2 '09 #6

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

Similar topics

5
by: Shay | last post by:
essentially I am trying to do some counts based on some assumptions in the recordset. So I get the RS back, put the values into a variable, move to the next record in the RS and compare what is in...
3
by: Svelte Poshy | last post by:
On the control of my form i want to give a command for creating fields in a table.However i receive the message error variable not defined. May i have some help as to where is my error? Dim...
3
by: blindsey | last post by:
Is there a tool that can take an Access database and generate SQL "CREATE TABLE" statements for all the tables in it?
2
by: Thelma Lubkin | last post by:
My ColorSet building form/subform now works beautifully, thanks to the help that I've gotten from people in this group. The working form displays the parent ColorSet record with the child records...
3
by: John | last post by:
Hi I am using create user wizard with sql server based membership/roles. I have the following questions; 1. How can I get rid of the security question and answer as I don't need it in my app?...
5
by: Hexman | last post by:
I've come up with an error which the solution eludes me. I get the error: >An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in HRTest.exe > >Additional...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
0
by: Steven Prasil | last post by:
When I start my VisualStudio 2005 it creates automatically new folders: D:\work\Visual Studio 2005 D:\work\Visual Studio 2005\Projects D:\work\Visual Studio 2005\Templates Yes, in VS menu ...
2
by: jarea | last post by:
I have read quite a bit about this error but I have yet to find the solution to my problem. I am trying to execute the following mysql statement: alter table line_items add...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.