Element button submitting form. How to disable?

1

I need to separate the form into 2 different divs, on the same page. I tried the following and it did not work:

    <div id="div1">
<form method="post">
<input type="text" name="Nome">
</form>
<button onclick="exibediv2()">
</div>
    <div id="div2">
<form method="post">
<input type="text" name="Cidade">
<input type="submit">
</form>
<button onclick="exibediv1()">
</div>

When I use submit on the second form, it does not recognize the value of the first input. How do I resolve this?

[ Added due feedback from comments ]

  

When I leave as a single <form> the first button acts as a    submit .

    
asked by anonymous 07.02.2016 / 18:58

1 answer

2

The button element is set by default to be of type submit type="submit" . Except for pre-IE8 version where button type="button" .

To disable the default type, simply specify within the tag itself:

<button type="button" />

For the specific case of the question, a suggestion how to solve:

<form method="post">
<div id="div1">
<input type="text" name="Nome">
<button type="button" onclick="exibediv2()">
</div>
<div id="div2">
<input type="text" name="Cidade">
<input type="submit">
<button type="button" onclick="exibediv1()">
</div>
</form>
    
07.02.2016 / 19:35