1π
β
Why are you comparing the text of selected option, just compare its value, thisβll be much simpler.
$("select").on('change',function(){
if($(this).val()=="blank")
$("#button").attr('disabled',true)
else
$("#button").attr('disabled',false)
});
But Please make sure that you have disabled button
on page load
.
There is two way to do this working. First, you can disable button
on page load
in jquery. Second, on page load
get the value of select
and check that if itβs value is blank
then disable the button
.
π€Poonam
0π
Your options text content is actually -
, notice the two spaces infront of the dash. The jQuery is reading those spaces and not counting -
the same as -
. Remove those preceding spaces and it should now work.
$("select").on('change', function() {
if ($(this).find('option:selected').text() == "-")
$("#button").attr('disabled', true)
else
$("#button").attr('disabled', false)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="{% url 'select_controller' id=i.ID %}" method="post">
<td>
<select class="form-control" name="controller" id="select_controller">
<option value="test">test</option>
<option value='blank'>-</option>
<option value="testing">testing</option>
</select>
</td>
<td>
<button id="button" class="btn btn-primary" type="submit" value="Submit">Send</button>
</td>
</form>
π€Wowsk
- Can't split django views into subfolders
- How to get spcific child page in django cms with {% show_menu_below_id %}?
- Multiple forms submitting with single view β Django
- Dynamic database selection based on URL in Django
- How do I fix Bootstrap from breaking grid?
0π
We may also use:
$('#button').prop('disabled',true);
Some explanation on .prop()
versus .attr()
usage here.
- How to supply a QuerySet to an included template?
- Django django.contrib.gis.db MultiPolygonField extract points
- Sorted/searchable StackedInline options
- More efficient way of writing this function? (Django, AJAX)
- Datatables with JSON Ajax datasource
Source:stackexchange.com