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 6744545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:05:48+00:00 2026-05-26T12:05:48+00:00

Because of a Flex bug uploading files in a secure environment , I’m attempting

  • 0

Because of a Flex bug uploading files in a secure environment, I’m attempting to hack together a workaround for this in javascript.

To do so, I’m attempting to create a hidden form in javascript, to which I’ll attach a file and some xml meta data, then send it to the server in a multipart form post. My first thought is to get this to work in HTML and then port this javascript code into my Flex project.

My first problem is attaching the file to the hidden form in javascript. I’m doing something wrong here. I’m pretty inexperienced with javascript so if there’s a better way to do this, I’m eager to learn.

Here’s the code I’m current playing with.

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>hidden form post demo</title>
   </head>

   <body>
      <script>
      
         //helper function to create the form
         function getNewSubmitForm(){
             var submitForm = document.createElement("FORM");
             document.body.appendChild(submitForm);
             submitForm.method = "POST";
             submitForm.enctype = "multipart/form-data";
             return submitForm;
         }
         
         //helper function to add elements to the form
         function createNewFormElement(inputForm, inputType, elementName, elementValue) {
             var inputElement = document.createElement("INPUT");
             inputElement.name = elementName;
             inputElement.type = inputType;
             try {
                inputElement.value = elementValue;
             } catch(err) {
                alert(err.description);
             }
             inputForm.appendChild(inputElement);
             return inputElement;
         }
         
         //function that creates the form, adds some elements
         //and then submits it
         function createFormAndSubmit(){
             var submitForm = getNewSubmitForm();
             var selectedFileElement = document.getElementById("selectedFile");
             var selectedFile = selectedFileElement.files[0];
             createNewFormElement(submitForm, "HIDDEN", "xml", "my xml");
             createNewFormElement(submitForm, "FILE", "selectedFile", selectedFile);
             submitForm.action= "my url";
             submitForm.submit();
         }
         
      </script>


      <div id="docList">
        <h2>Documentation List</h2>
        <ul id="docs"></ul>
      </div>

      <input type="file" value="Click to create select file" id="selectedFile"/>
      <input type="button" value="Click to create form and submit" onclick="createFormAndSubmit()"/>
</body>

</html>

You can see, I have a try/catch block in createNewFormElement. An exception is being thrown there, but the message says "undefined".

In FireBug, I can see that the elementValue is set to a File object, so I’m not really sure what’s going on.

  • 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-05-26T12:05:49+00:00Added an answer on May 26, 2026 at 12:05 pm

    For security reasons, you cannot set the value attribute of an input[type=file]. Your current code doesn’t need JavaScript, and can be written using pure HTML:

    <form method="post" enctype="multipart/form-data" action="myurl">
        <input type="file" value="Click to create select file" name="selectedFile" />
        <input type="hidden" name="xml" value="my xml" />
        <input type="submit" value="Click to create form and submit" />
    </form>
    

    If you want to, it’s possible to dynamically add additional non-file form elements, by binding an event to the onsubmit handler.

    <form ... onsubmit="addMoreinputs();" id="aForm">
    ...
    <script>
    function addMoreInputs(){
        var form = document.getElementById("aForm");
        // ...create and append extra elements.
        // once the function has finished, the form will be submitted, because
        //  the input[type=submit] element has been clicked.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use flex and bison to create a filter, because I want
I had to reformat my question because I realized I was using incorrect flex
I'm writing a mock backend service for my flex application. Because I will likely
Because I've made .cpp files and then transferred them into .h files, the only
I need Flex code to support HTML5 File API. Because I need to support
can someone help me understand this because it's working in as3 but not so
I may be missing something here because I thought this might be really easy
I noticed that Eclipse (Flex Builder) generates hundreds of metadata files. Should I check
If you create a pure ActionScript project in Flex Builder 3 and want to
I'm calling a javascript function from a Flex application and it's quite annoying that

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.