Change the action of a form as per condition

Asked

Viewed 488 times

0

I have a form that does an update.

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

  • I changed your question, I had a lot of information not needed in my view, if you feel that I changed the meaning of your question, just click here and click reverse

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 working:

  • 1

    It worked as I needed it. I thought it would be complicated and you did it with a few lines. Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.