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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:25:26+00:00 2026-06-09T18:25:26+00:00

I am new to forms, and Javascript, so please be forgiving. I have a

  • 0

I am new to forms, and Javascript, so please be forgiving.

I have a form that looks like this:

<form method="post" action="control" name="myform">
<input type="submit" name="Name" value="Do A"/>
<input type="submit" name="Name" value="Do B" />
<input type="submit" name="Name" value="Do C" />
<input type="submit" name="Name" value="Close" />
</form>

I need to change this so that there are two buttons, and the form is submitted using javascript dependent on some external conditions, so I want it to look something like this:

<form method="post" action="control" name="myform">
<script>
function submitForm(form){
    if(someConditionA){
        submit the form so that the script performs same action as if the button Do A had been clicked
    } if (someConditionB){
        submit the form so that the script performs same action as if the button Do B had been clicked
    } if (someConditionC){
        submit the form so that the script performs same action as if the button Do C had been clicked
    }
}

function closeForm(form){
    window.close();
}
</script>
<button name="doAction" onClick="SubmitForm(this.form)">Do Action<\button>
<button name="close" onClick="SubmitForm(this.form)">Close<\button>
</form>

How can I implement the function submitForm?

Thanks

  • 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-09T18:25:28+00:00Added an answer on June 9, 2026 at 6:25 pm

    Add a hidden field with the same name as the original submit buttons:

    <input type="HIDDEN" name="Name" value=""/>
    

    Set the value of that field based on your conditions:

    function submitForm(form){
        if(someConditionA){
            form.Name.value = "Do A";
        } if (someConditionB){
            form.Name.value = "Do B";
        } if (someConditionC){
            form.Name.value = "Do C";
        }
        form.submit();
    }
    

    Change the new Close button to this:

    <button name="close" onClick="this.form.Name.value='Close';this.form.submit();">Close<\button>
    

    I haven’t tested this, so it may contain a mistake or two, but that’s the general idea. (+1 for ‘this.form’, not many folks know about that, nice.)

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

Sidebar

Related Questions

I am new to C#, Windows Forms, and datagridviews. I have a tabbed form:
Please help me to refactore this Javascript code. There is big form for scheduled
I am fairly new to AJAX so please forgive me. I have to forms
I am very new to Javascript so please be patient. I have a script
i would like someone with experience in JavaScript to please look through this script
I am new to Javascript so please bear with me. I have a Javascript
I have the following form and javascript function on my web page. This is
I'm fairly new to javascript and I'm trying to make an form for my
I'm completely new to javascript, but I'm trying to create a beta form for
I am relatively new to Javascript so I'm hoping this is a simple mistake.

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.