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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:52:39+00:00 2026-05-13T08:52:39+00:00

I have the worlds most simple javascript function: fnSubmit() { window.print(); document.formname.submit(); } Which

  • 0

I have the worlds most simple javascript function:

fnSubmit()
{
  window.print();
  document.formname.submit();
}

Which is called by:

<button type="button" id="submit" onclick="fnSubmit()">Submit</button>

All is well and good, the print dialog shows up, however after printing or canceling the print I get the following error:

“document.formname.submit is not a function”

My form is defined as follows: (obviously I am not using formname in the actual code but you get the idea)

<form name="formname" id="formname" method="post" action="<?=$_SERVER['SCRIPT_NAME']?>">

Obviously I am not trying to do anything special here and I have used similar approaches in the past, what in the world am I missing here?

  • 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-13T08:52:39+00:00Added an answer on May 13, 2026 at 8:52 am

    In short: change the id of your submit button to something different than “submit”. Also, don’t set the name to this value either.

    Now, some deeper insight. The general case is that document.formname.submit is a method that, when called, will submit the form. However, in your example, document.formname.submit is not a method anymore, but the DOM node representing the button.

    This happens because elements of a form are available as attributes of its DOM node, via their name and id attributes. This wording is a bit confusing, so here comes an example:

    <form name="example" id="example" action="/">
      <input type="text" name="exampleField" />
      <button type="button" name="submit" onclick="document.example.submit(); return false;">Submit</button>
    </form>
    

    On this example, document.forms.example.exampleField is a DOM node representing the field with name “exampleField”. You can use JS to access its properties such as its value: document.forms.example.exampleField.value.

    However, on this example there is an element of the form called “submit”, and this is the submit button, which can be accessed with document.forms.example.submit. This overwrites the previous value, which was the function that allows you to submit the form.

    EDIT:

    If renaming the field isn’t good for you, there is another solution. Shortly before writing this, I left the question on the site and got a response in the form of a neat JavaScript hack:

    function hack() {
      var form = document.createElement("form");
      var myForm = document.example;
      form.submit.apply(myForm);
    }
    

    See How to reliably submit an HTML form with JavaScript? for complete details

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

Sidebar

Related Questions

I have this caption function that worlds great. If I fill in the alt
I have a table called keywords. It's simple, two columns - id and keyword.
I have the following Javascript/jQuery function: function addEventHandler(){ $(div).mouseenter(function() { $(this).html(Over); }).mouseleave(function() { $(this).html(Out);
I have a window with a simple frame element within it (we'll call it
I have the most simple SQL SELECT * FROM words It has 13000 words
I have most bizarre and probably simple to solve problem but it's driving me
World's most convuluted title I know, an example should explain it better. I have
I'm torn between two worlds, I have this very intuitive (but intricate) mechanism in
I come from the ruby and python worlds where we have many libraries that
I have class World which manages creation of object... After creation it calls afterCreation

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.