Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8441853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:40:53+00:00 2026-06-10T08:40:53+00:00

I’m dynamically creating a file upload form. I attach the dynamically created form to

  • 0

I’m dynamically creating a file upload form. I attach the dynamically created form to a dynamically created div. So far so good.

Two of the form elements show up as valid form fields: A type=text field, and a type=file field.

After appendChild-ing the two type=image fields, the image buttons do indeed show up in the pop-up form, but for some reason I’m getting a javascript error “Error: TypeError: document.forms.fileform.Upload is undefined”.

An alert prompt reveals that document.forms[‘fileform’].length is only two elements, not the four I expect.

Code that creates the div and the form within the div:

if(! document.getElementById("fileformdiv")){
  var fileformdiv = document.createElement("div");
  fileformdiv.setAttribute("id","fileformdiv");
  fileformdiv.setAttribute("style","position:relative;top:-200px;left:-250px;height:160px;line-height:30px;width:220px;border:#aaa 1px solid;background:#eee;z-index:10;text-align:left;padding:10px 10px 10px 10px;");
  document.getElementById("stampContainer").appendChild(fileformdiv);

  var fileform = document.createElement("form");
  fileform.setAttribute("enctype","multipart/form-data");
  fileform.setAttribute("id","fileform");
  fileform.setAttribute("name","fileform");

  var descriptionprompt = document.createTextNode("Say something about this file:");

  var filedescription = document.createElement("input");
  filedescription.setAttribute("id","filedescription");
  filedescription.setAttribute("name","filedescription");
  filedescription.setAttribute("type","text");
  filedescription.setAttribute("style","position:relative;width:200px;height:30px;margin:10px 10px 10px 0px;");

  var filename = document.createElement("input");
  filename.setAttribute("id","filename");
  filename.setAttribute("name","filename");
  filename.setAttribute("type","file");
  filename.setAttribute("style","position:relative;width:200px;margin:10px 10px 10px 0px;");

  var uploadbutton = document.createElement("input");
  uploadbutton.setAttribute("name","Upload");
  uploadbutton.setAttribute("id","Upload");
  uploadbutton.setAttribute("type","image");
  uploadbutton.setAttribute("style","position:relative;margin:0px 0px 0px 60px;width:80px;height:30px;");
  uploadbutton.setAttribute("src",baseUrl+"images/upload.gif");

  var cancelbutton = document.createElement("input");
  cancelbutton.setAttribute("name","Cancel");
  cancelbutton.setAttribute("id","Cancel");
  cancelbutton.setAttribute("type","image");
  cancelbutton.setAttribute("style","position:relative;margin:-30px 0px 0px 140px;width:80px;height:30px;");
  cancelbutton.setAttribute("src",baseUrl+"images/cancel.gif");

  var linebreak = document.createElement("br");


  document.getElementById("fileformdiv").appendChild(fileform);
  document.forms['fileform'].appendChild(descriptionprompt);
  document.forms['fileform'].appendChild(filedescription);
  document.forms['fileform'].appendChild(linebreak);
  document.forms['fileform'].appendChild(filename);
  document.forms['fileform'].appendChild(linebreak);
  document.forms['fileform'].appendChild(uploadbutton);
  document.forms['fileform'].appendChild(cancelbutton);

  document.forms['fileform']['Upload'].onclick = function() { submitFile(); return false; };
  document.forms['fileform']['Cancel'].onclick = function() { document.getElementById("fileformdiv").parentNode.removeChild(document.getElementById("fileformdiv")); };

  for(i=0;i<document.forms['fileform'].length;i++){
     alert(document.forms['fileform'][i].name);
  }
}

I should add that this form works just fine if I use the plain-jane type=”submit” rather than a type=”image” button. But that’s not what I want, and I don’t settle for mediocre.

Thanks to Musa for leading me to a solution.

I changed:

document.forms['fileform']['Upload'].onclick = function() { submitFile(); return false; };


document.forms['fileform']['Cancel'].onclick = function() { document.getElementById("fileformdiv").parentNode.removeChild(document.getElementById("fileformdiv")); };

to:

submitbutton.onclick = function() { submitFile(); return false; };


cancelbutton.onclick = function() { document.getElementById("fileformdiv").parentNode.removeChild(document.getElementById("fileformdiv")); };

…and voila, the script works without errors. Still, the fields don’t show up as form fields. But it doesn’t matter practically speaking, since I can attach onclicks to them and they do what they are supposed to do.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:40:55+00:00Added an answer on June 10, 2026 at 8:40 am

    I did some searching and <input type="image"> elements are not included in the form elements collection see Remarks http://msdn.microsoft.com/en-us/library/ms537449(v=VS.85).aspx, so you cant reference it from the form elements. As you already have references to the elements you should use it

    if(! document.getElementById("fileformdiv")){
      var fileformdiv = document.createElement("div");
      fileformdiv.setAttribute("id","fileformdiv");
      fileformdiv.setAttribute("style","position:relative;top:-200px;left:-250px;height:160px;line-height:30px;width:220px;border:#aaa 1px solid;background:#eee;z-index:10;text-align:left;padding:10px 10px 10px 10px;");
      document.getElementById("stampContainer").appendChild(fileformdiv);
    
      var fileform = document.createElement("form");
      fileform.setAttribute("enctype","multipart/form-data");
      fileform.setAttribute("id","fileform");
      fileform.setAttribute("name","fileform");
    
      var descriptionprompt = document.createTextNode("Say something about this file:");
    
      var filedescription = document.createElement("input");
      filedescription.setAttribute("id","filedescription");
      filedescription.setAttribute("name","filedescription");
      filedescription.setAttribute("type","text");
      filedescription.setAttribute("style","position:relative;width:200px;height:30px;margin:10px 10px 10px 0px;");
    
      var filename = document.createElement("input");
      filename.setAttribute("id","filename");
      filename.setAttribute("name","filename");
      filename.setAttribute("type","file");
      filename.setAttribute("style","position:relative;width:200px;margin:10px 10px 10px 0px;");
    
      var uploadbutton = document.createElement("input");
      uploadbutton.setAttribute("name","Upload");
      uploadbutton.setAttribute("id","Upload");
      uploadbutton.setAttribute("type","image");
      uploadbutton.setAttribute("style","position:relative;margin:0px 0px 0px 60px;width:80px;height:30px;");
      uploadbutton.setAttribute("src",baseUrl+"images/upload.gif");
    
      var cancelbutton = document.createElement("input");
      cancelbutton.setAttribute("name","Cancel");
      cancelbutton.setAttribute("id","Cancel");
      cancelbutton.setAttribute("type","image");
      cancelbutton.setAttribute("style","position:relative;margin:-30px 0px 0px 140px;width:80px;height:30px;");
      cancelbutton.setAttribute("src",baseUrl+"images/cancel.gif");
    
      var linebreak = document.createElement("br");
    
    
      fileformdiv.appendChild(fileform);
      fileform.appendChild(descriptionprompt);
      fileform.appendChild(filedescription);
      fileform.appendChild(linebreak);
      fileform.appendChild(filename);
      fileform.appendChild(linebreak);
      fileform.appendChild(uploadbutton);
      fileform.appendChild(cancelbutton);
    
      uploadbutton.onclick = function() { submitFile(); return false; };
      cancelbutton.onclick = function() { fileformdiv.parentNode.removeChild(fileformdiv); };
    
      for(i=0;i<fileform.length;i++){
         alert(fileform[i].name);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.