Reputation: 1525
I want to be able to select only 1 checkbox at a time in Datatables.
In the example below, multiple rows can be selected. How can I go about only allowing one row to be selected at a time?
http://datatables.net/examples/api/form.html
Upvotes: 0
Views: 2969
Reputation: 89
var _MainDataTable = $('#dataTable').DataTable();
...
$("#dataTable").on('click', 'tr', function () {
if (_MainDataTable.$(".selected").length > 1) {
_MainDataTable.$(".selected").removeClass('selected');
$(this).addClass("selected");
}
});
Upvotes: 0
Reputation: 501
How to select first row of the first table in an html page using jQuery? Selects one row in a given table. You could use jQuery to achieve it.
Upvotes: 1
Reputation: 7152
You should use the radio button,
<form action="path/to/form_submit_script.php" method="get">
<input type="radio" name="red" value="Red" /> Red<br />
<input type="radio" name="blue" value="Blue" /> Blue<br />
<input type="radio" name="green" value="Green" /> Green<br />
<input type="submit" value="Submit">
</form>
Here is the working example jsfiddle example
Upvotes: 0
Reputation: 2534
You could use Radio buttons instead of checkboxes.
Example:
<input type="radio" name="fieldName" value="check1" />
<input type="radio" name="fieldName" value="check2" />
<input type="radio" name="fieldName" value="check3" />
<input type="radio" name="fieldName" value="check4" />
The "name" attribute is what groups the radio buttons together, the "value" attribute is what will differentiate them.
Upvotes: 3