Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap html click button without submit form

Here is my code

        <form class="form-horizontal">

          <div class="control-group">
            <div class="controls">
              <button onclick="javascript:add_user_group(2);" class="btn">add</button>
            </div>
          </div>

        <table id="users-table" class="table table-striped" >
          <thead>
            <tr>
              <th>User Name</th>
              <th>Delete</th>            
            </tr>
          </thead>
          <tbody>

          </tbody>
        </table>

      </form>             

I just want to add a new row to a table when a add button clicked, but it seems a click of the add button triggers a submission of form.

Isn't is only a button with

 type=submit

to submit form. Or any button in a form triggers a submission of form ?

like image 280
icn Avatar asked Feb 22 '13 19:02

icn


1 Answers

No need to use Javascript. Just set type="button" to overwrite the implicit type="submit". This can also be found in the HTML5 specs as mentioned here: https://stackoverflow.com/a/9643866/2175370

like image 58
Maurice Schleußinger Avatar answered Nov 15 '22 12:11

Maurice Schleußinger