Bootstrap html 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 the table when I click the add button, but it seems that clicking the add button causes the form to be submitted.
Not just a button with
type=submit
submit the form. Or does any button on the form trigger the presentation of the form?
+5
2 answers
No need to use Javascript. Just set type="button"to replace implicit type=submit. It can also be found in the HTML5 specs as stated here: fooobar.com/questions/116709 / ...
+29