473,786 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE7 does not create additional fields

105 New Member
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 2175
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
I suppose that's one way of doing it. Glad to see that you got it working.
Jan 22 '09 #4
irfanagaria1810
1 New Member
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 Recognized Expert Moderator MVP
You're welcome, and welcome to Bytes!

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

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

Similar topics

5
3145
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 the variable to the value in the next record in the recordset and do a count. Then overwrite the value in the variables and do the same for the next record and so. But this runs extremly slow. 5000 records takes about 10 minutes in IE6 and I...
3
10384
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 dbs As Database Dim tdf As DAO.TableDef Dim fld As DAO.Field Dim prp As DAO.Property Dim idx As DAO.Index
3
3876
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
2689
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 displayed in the subform below it. ParentTable fields: ColorsetName Classsize ChildTable fields: ColorsetName ColorSequenceNumber RedVal GreenVal BlueVal I've now been asked to allow the user to generate a new ColorSet from
3
8349
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? 2. How can I get the control to send an email to the "office" so they can authorise the account before it can be activated for the user?
5
3752
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 information: Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype. It occurs when I attempt to add a new record. I've stripped out much of the code, leaving the pertinent (I hope) info. ...
55
6249
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 C# in some way? Or maybe no, because it is similar to a global variable (with its scope restricted) which C# is dead against? Zytan
0
1358
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 tools -options -Projects and Solutions
2
43962
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 constraint fk_line_item_products foreign key (product_id) references products(id) I have also tried the following statement with the same result:
0
9650
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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
10164
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...
0
9962
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
8992
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
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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

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.