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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:02:29+00:00 2026-06-02T03:02:29+00:00

I’m trying to use the submit-function in javascript to submit a form. The reason

  • 0

I’m trying to use the submit-function in javascript to submit a form. The reason I’m not using a submit button is that I want to ask the user if really wants to submit the form. Here is the code:

<?php    
if(isset($_POST['submit1']))
die("Submit successfull!");
?>

<!--Javascript submit question.-->
<script type="text/javascript">
function question_submit() {
    if(confirm('Are you sure you want to submit?')) {
        return true;
    }

    else {
        alert('You have not submitted this form');
        return false;
    }
}
</script>

<!--The form-->
<form action='test.php' method='POST'>
<input type='button' name='submit1' value='Submit' onClick="if(question_submit()) { this.form.submit(); }" />
</form>

Result: The popups works great, it just never wants to submit the form and so “Submit successfull!” never shows up.

The message is not even shown when I add a real submit button to the page. It’s like the POST-data won’t work.
But when I add a PHP-code and die-function för the submit-button the thing will work and “REal Submit Works” will show up, which is strange because the buttons code is first.

<?php
if(isset($submit1))
die("Submit successfull!");
if(isset($_POST['realsubmitbutton']))
die("REal Submit Works");
?>

I I’ve also tried to change the onClick to just contain the javascript submit function. Like this: onClick=”this.form.submit();”. But that won’t work either. So my question is, what’s wrong with the code and why won’t it work?

Can’t buttons send it’s value with POST?

  • 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-02T03:02:30+00:00Added an answer on June 2, 2026 at 3:02 am

    I’ve read all your answers and have finished the code. It now works with both clicking on the button or pressing Enter key. The javascript runs correctly either way and the form gets submitted.
    This is the code:

    <?php
    if(!empty($_POST['justaname']))
    die("Submit successfull!");
    ?>
    
    <!--Javascript submit question.-->
    <script type="text/javascript">
    function question_submit() {
        if(confirm('Are you sure you want to submit?')) {
            document.getElementById("myform").submit();
        }
    
        else {
            alert('You have not submitted this form');
        }
    }
    </script>
    
    <!--The form-->
    <form action='test.php' method='POST' id="myform" onSubmit="event.preventDefault(); question_submit();">
    <input type="text" name='justaname' />
    <input type='button' name='submit1' value='Submit' onClick="question_submit()" />
    </form>
    

    Thanks for all the answers and hope this is helpfull for someone.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I

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.