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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:54:15+00:00 2026-06-01T01:54:15+00:00

Trying to set a flag in the post to allow processing or not. The

  • 0

Trying to set a flag in the post to allow processing or not. The javascript isn’t working for me I want to have a dialog box pop up and then set a hidden post bool 0 for canceled and 1 for ok. Is there a better way to set a post value based on the confirm return? Everything I search for brings up ASP.NET and it’s postBack value.

The form is generated using simple JSP (I know it’s outdated and JSTL is better this suites my needs):

<form name="delPlayers" method="post" action="deletePlayer.jsp" class="col6 leftpad3 rightpad3">
   <input type="hidden" name="confirmed" value="0" />
   <select name="playerName">
   <% while (results.next())
      {
         out.print("<option value=\"");
         out.print(results.getString("username"));
         out.print("\">");
         out.print(results.getString("username"));
         out.print("</option>");
      } %>
   </select>
   <input type="submit" name="Submit" class="button" value="Submit" onSubmit="return confirmSubmit()" />
</form>

How I was trying to check the confirm return and set the value before the post.

<script type="text/javascript">
<!--
   function confirmSubmit()
   {
      var r = confirm("Remove " + document.forms['delPlayers']["playerName"].value + "?");
      if (r)
         document.forms['delPlayers']["confirmed"].value = r;
         return true ;
      else
         return false ;
   }
-->
</script>
  • 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-01T01:54:16+00:00Added an answer on June 1, 2026 at 1:54 am

    This part :

     onSubmit="return confirmSubmit()"
    

    should appear inside the <form> tag, not the <input submit> tag. Like this :

    <form onSubmit="return confirmSubmit()" name="delPlayers" method="post" action="deletePlayer.jsp" class="col6 leftpad3 rightpad3">
    

    [EDIT]

    You didn’t get it working cause your javascript structure is not as good as needed. I tried to change your code into something like this, and things seem to be better:

    if (r){
        document.forms['delPlayers']["confirmed"].value = r;
        return true ;
    }else{
        return false ;
    }
    

    Just remember to always use the curly brackets { and } when you write if command inside javascript. You’re not obliged to use them, but it’s a god habit to avoid such nonsensical problem like this.

    Technical note : In JS, the if(condition) without curly brakets {} works with only 1 line of command right after it . In your case, there were 2 command, so the “else” statment was illegal. That’s the reason why you alway should use if with curly brackets

    if (condition)
          foo()
    else
          bar()
    

    is OK. But

    if (condition)
          foo()
          any_extra_command();
    else
          bar()
    

    will cause an error. So the best for all case was :

    if (condition){
          foo();
          any_extra_command();
          ......
          anything_you_want_else();
    }else{
          bar()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up argparse on my python program but it's not working.
I'm trying to set flag that causes the Read Only check box to appear
I am trying to set a flag to show or hide a page element,
I'm trying to set the RequireAdministrator manifest flag on an executable I'm building with
I'm trying to create a small set of classes implementing a safe flag pattern,
So recently I have been trying to set up a Vim-based iOS workflow. I
I am trying to set the DF (don't fragment flag) for sending packets using
I'm trying to set up a box to compile my project on windows. This
Im trying set the single table inheritance model type in a form. So i
I am trying set up databinding as described in the title. The problem 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.