Change the action of a form according to the condition

0

I have a form that does an update.

But I wanted to put a checkbox type input that when checked, changed the action of my form to delete.

    
asked by anonymous 09.03.2017 / 03:28

1 answer

5

The simplest way to get this result:

function suaFuncao(option) {
  if (option) {
    document.getElementById("seu_form").action = "delete";
  } else {
    document.getElementById("seu_form").action = "update";
  }
}
<form id="seu_form" action="update">
  Deseja fazer um delete?<input type="checkbox" onclick="suaFuncao(this.checked)">
</form>

See it working:

    
09.03.2017 / 03:41