D
D
Dutymy2021-07-11 02:35:27
JavaScript
Dutymy, 2021-07-11 02:35:27

How to put multiple buttons on one form?

hello i have a form

<form action="" >
  <input type="text" >
  <button type="submit">send</button>
  <button onclick="changeColor()">make green</button>
</form>
<script>
function changeColor(){
document.body.style.backgroundColor="green";
}
</script>

But how to make it so that the form is not sent / not checked for change color

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Masla552, 2021-07-11
@Dutymy

The last button should be changed like this:

<button type="button" onclick="changeColor()">make green</button>

T
TechZone, 2021-07-11
@TechZone

The second button must have a type (type) set

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question