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 ?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With