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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:41:57+00:00 2026-06-15T18:41:57+00:00

I am trying to create an automatic file download when a visitor submits a

  • 0

I am trying to create an automatic file download when a visitor submits a validated opt-in form. I would like to initiate the download using a Javascript function as an onsubmit() event. Here is the code I am working with I am already using the form action= to submit the form data to a database and there is already Javascript in place to validate the form. I just need to add the download function.

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE html
   PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>

  <style type="text/css" xml:space="preserve">
  BODY, P,TD{ font-family: Arial,Verdana,Helvetica, sans-serif; font-size: 10pt }
  A{font-family: Arial,Verdana,Helvetica, sans-serif;}
  B {   font-family : Arial, Helvetica, sans-serif; font-size : 12px;font-  
  weight     
 : bold;}
  .error_strings{ font-family:Verdana; font-size:14px; color:#660000;}
  </style>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"> 
   </script>
 <script type="text/javascript" 
 src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script language="JavaScript" src="gen_validatorv4.js"
type="text/javascript" xml:space="preserve"></script>



   <script type="text/javascipt">
   var downloadURL = function downloadURL(url) {
  var iframe;
  var hiddenIFrameID = 'hiddenDownloader';
  iframe = document.getElementById(hiddenIFrameID);
   if (iframe === null) {
    iframe = document.createElement('iframe');  
    iframe.id = hiddenIFrameID;
    iframe.style.display = 'none';
    document.body.appendChild(iframe);
   }
  iframe.src = 'http://healthyweightnaturally.com/file-download/download.php?   
   download_file=integrative_nutrition_ebook.pdf';   
  }
   </script>
 </head>
 <body>



<form name="myform" id="myform" method="post"  
   action="https://www.example.com/FormHTML.aspx" onSubmit="return downloadURL(url);"> 

        
     <table cellspacing="2" cellpadding="2" border="0">
    <tr>
      <td align="right">
        First Name
      </td>
      <td>
        <input type="text" name="FirstName" />
      </td>
    </tr>
    <tr>
      <td align="right">
        Last Name
      </td>
      <td>
        <input type="text" name="LastName" />
      </td>
    </tr>
    <tr>
      <td align="right">
        Email *
      </td>
      <td>
        <input type="text" name="Email" />
      </td>
    </tr>


  
    <tr>
      <td align="right"></td>
      <td>
        <div id="myform_errorloc" class="error_strings">
        </div>
      </td>
    </tr>
    <tr>
      <td align="right"></td>
      <td>
        <input style="padding-left:10px;" src="http://healthyweightnaturally.com/file-  
     download/download-button.png" type="image" value="submit" value="Submit" />
      </td>
    </tr>
  </table>
    <div style="visibility:hidden"> 
    <iframe name="ifr1" width="20" height="20" id="hiddenIFrameID"></iframe> 
    </div> 
   </form>
 <script language="JavaScript" type="text/javascript"
    xml:space="preserve">//<![CDATA[
   //You should create the validator only after the definition of the HTML form
   var frmvalidator  = new Validator("myform");
  frmvalidator.EnableOnPageErrorDisplaySingleBox();
  frmvalidator.EnableMsgsTogether();

 frmvalidator.addValidation("FirstName","req","Please enter your First Name");
 frmvalidator.addValidation("FirstName","maxlen=20",    "Max length for FirstName   
 is 20");
 frmvalidator.addValidation("FirstName","alpha_s","Name can contain alphabetic chars    
 only");

 frmvalidator.addValidation("LastName","req","Please enter your Last Name");
 frmvalidator.addValidation("LastName","maxlen=20","For LastName, Max length is 20");

 frmvalidator.addValidation("Email","maxlen=50");
 frmvalidator.addValidation("Email","req");
 frmvalidator.addValidation("Email","email");

 //]]>
 </script>

 </body>

 </html>

I want to use onsubmit instead of onclick because I need to make sure that the form has been validated before the file is able to be downloaded.
I am somewhat new to Javascript and have been struggling with this. I would greatly appreciate someone’s assistance. The closest thing I found to an answer can be seen at HTML OnSubmit: Download OR HTML, but since they never gave any code examples it does not help me see the solution.

  • 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-15T18:41:58+00:00Added an answer on June 15, 2026 at 6:41 pm

    You can use jQuery plugin http://jqueryfiledownload.apphb.com/, which I found here Download File Using Javascript/jQuery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an Android library JAR and would like to use ant
I am trying to create and automatic preview mechanism for some content entered with
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
I'm trying to create an .sav file programmatically without having to use SPSS automation
I'm trying to create a Service using Automator that simply calls textutil convert. Eventually,
I'm trying to automate the download of a file from a website. Normally to
I'm trying to create a simple text editor like Textedit for Mac OS X,
I'm trying to export HTML file with pictures to Excel using C++ OLE Automation.
Currently I'm trying to set up a Form to create a News-Item from. The

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.