Javascript form submits even when variable is false

user3591590

So I am trying to have the user confirm their action before they submit the form, so I tried using the confirm box. When I tested it, even when I pressed Cancel in the confirm box the form submitted. So I tried just setting variable 'c' to false and then saying if c==true, submit the form, and the form still submitted! I don't understand why this is happening. Any help would be appreciated!

So just to be clear, the form still submits in the following code:

<button onclick=\"extendBids('$studentID')\">Extend Bid</button>
    <input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>


function extendBids(studentID) {
   document.getElementById(studentID+" 2").checked=true;
   //var c=confirm("Are you sure? This action cannot be undone.");
    var c=false;
    if (c==true){
      document.forms["addToRush"].submit();
   }
}
brainless coder

Try this -

<button onclick=\"extendBids('$studentID');\">Extend Bid</button>
    <input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>


function extendBids(studentID) {
   document.getElementById(studentID+" 2").checked=true;
   if(confirm("Are you sure? This action cannot be undone.")){
      document.forms["addToRush"].submit();
      return true;
   }
   return false;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

onsubmit still submits form even on return false from ajax verification

From Dev

Jquery AJAX submits the form even if confirm() method is false

From Dev

Form still submits even with preventDefault

From Dev

Form submitting even when it is returning false

From Dev

form submits even when I click cancel in confirm form submission dialog

From Dev

async issues with form submission following client-side geocoding - form always submits even if validate function returns false

From Dev

I have a post form that submits but "$_POST" variable is empty even though my web inspector indicates otherwise

From Dev

custom captcha submits form even if code is not correct

From Dev

My form submits even with empty required fields

From Dev

javascript form validation always returns true even when condition matches and should returns false

From Dev

JavaScript form validation: if statement regarded select tag runs even when parameter is false

From Dev

Form submits when "<button>" is clicked

From Dev

jQuery - Form still submits with return false

From Dev

How would I pass in a variable when someone submits a form without changing the URL?

From Dev

Chrome Alert Box Submits Page Even if Returning False

From Dev

Rails form helper checkbox always checked even when {checked: false}

From Dev

codeigniter form validation always returns false even when rules met

From Dev

Jquery validator submits when bootstrap form is invalid

From Dev

How to display message when a user submits the form

From Dev

when I click inside textarea it submits form

From Dev

Identify/Get the city when the form submits

From Dev

Javascript code submits form on the same page in Mozilla

From Dev

javascript confirm cancel still submits form

From Dev

HTML form with 3 submits, But JavaScript not working

From Dev

How is a local variable created even when IF condition evaluates to false in Ruby?

From Dev

MVC @Html.CheckboxFor submits true,false on form submission

From Dev

When I add remote to Jquery Validate form submits when invalid

From Dev

Javascript: when one variable is true, set all other variable to false

From Dev

Form automatically submits when I don't want it to?

Related Related

  1. 1

    onsubmit still submits form even on return false from ajax verification

  2. 2

    Jquery AJAX submits the form even if confirm() method is false

  3. 3

    Form still submits even with preventDefault

  4. 4

    Form submitting even when it is returning false

  5. 5

    form submits even when I click cancel in confirm form submission dialog

  6. 6

    async issues with form submission following client-side geocoding - form always submits even if validate function returns false

  7. 7

    I have a post form that submits but "$_POST" variable is empty even though my web inspector indicates otherwise

  8. 8

    custom captcha submits form even if code is not correct

  9. 9

    My form submits even with empty required fields

  10. 10

    javascript form validation always returns true even when condition matches and should returns false

  11. 11

    JavaScript form validation: if statement regarded select tag runs even when parameter is false

  12. 12

    Form submits when "<button>" is clicked

  13. 13

    jQuery - Form still submits with return false

  14. 14

    How would I pass in a variable when someone submits a form without changing the URL?

  15. 15

    Chrome Alert Box Submits Page Even if Returning False

  16. 16

    Rails form helper checkbox always checked even when {checked: false}

  17. 17

    codeigniter form validation always returns false even when rules met

  18. 18

    Jquery validator submits when bootstrap form is invalid

  19. 19

    How to display message when a user submits the form

  20. 20

    when I click inside textarea it submits form

  21. 21

    Identify/Get the city when the form submits

  22. 22

    Javascript code submits form on the same page in Mozilla

  23. 23

    javascript confirm cancel still submits form

  24. 24

    HTML form with 3 submits, But JavaScript not working

  25. 25

    How is a local variable created even when IF condition evaluates to false in Ruby?

  26. 26

    MVC @Html.CheckboxFor submits true,false on form submission

  27. 27

    When I add remote to Jquery Validate form submits when invalid

  28. 28

    Javascript: when one variable is true, set all other variable to false

  29. 29

    Form automatically submits when I don't want it to?

HotTag

Archive