I'm looking for using Javascript in order to enable/disable submit button. This button should respect both following conditions :
- Enable : if checkbox is checked AND dropdown list value set
- Disable : if both or one of previous conditions are not good (checkbox unchecked or date value not set)
This is my code :
function checkValid() {
var cbChecked = $(".fake-radio").is(":checked"); // check if checked
var selectelem = document.getElementById('year');
var btnelem = document.getElementById('document-button');
btnelem.disabled = !selectelem.value;
}
And this is my html part :
<table id="document-table">
<thead>
<tr>
<th>{% trans 'Choice' %}</th>
<th>{% trans 'Document title' %}</th>
</tr>
</thead>
<tbody>
{% for document in query_document %}
<tr>
<td><input type="checkbox" class="fake-radio" id="document-checkbox" name="DocumentChoice"
value="{{ document.id }}"></td>
</tr>
{% endfor %}
</tbody>
</table>
<select id="year" name="q1year" value="{{ request.get.q1year }}" required>
<option selected="selected">
<option value="" selected disabled hidden></option>
</option>
</select>
<button class="btn btn-default" id="document-button" type="submit"
name="UpdateDocument">{% trans "Submit" %}</button>
I'm pretty new with Javascript
EDIT :
I made this, is it true ?
function checkValid() {
var cbChecked = $(".fake-radio").is(":checked"); // check if checked
var selectelem = document.getElementById('year');
var btnelem = document.getElementById('document-button');
btnelem.disabled = !selectelem.value;
var dropdown_value = btnelem.disabled
$("#document-button").prop("disabled", !cbChecked || dropdown_value);
}