0

I'm a bit of a Javascript noob but I need to submit a form using "post" in Javascript to a website, but I am using some conditions in my code and it looks something like this:

function submitForm()
{
   if(condition == true)
           {
               //submit the form
           }
           else{
               //do not submit the form
           }
}

Is this possible to do? I couldn't find anything online but I thought I might ask here before I try and figure out al alternative.

Might be worth mentioning that this function gets called from a button's onclick in HTML as an event.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Note in the duplicate I marked that [this answer](https://stackoverflow.com/a/8664535/519413) is the better approach. Also, you should hook the event to the `submit` event of the `form` element, not the click of the button. This is for accessibility reasons, among many others. – Rory McCrossan Oct 02 '22 at 19:28
  • 1
    Please do not edit your question into a brand new one. Instead please ask a [new one](https://stackoverflow.com/questions/ask). – Ethan Oct 02 '22 at 23:16

0 Answers0