Reputation: 907
I have a .cshtml
view that has a button and a text box that is a datepicker. How do I disable the button with id = "submitButton"
if the textbox is null? Thanks
<input id="submitButton" type="submit" value="blah" disabled="@ViewBag.blah"
class="btn btn-default" />
@Html.Label("my label:")
@Html.TextBox("Closed", "", new { @class = "datepicker" })
Upvotes: 0
Views: 661
Reputation: 289
You can do it in several different ways, easiest using javascript:
$(".datepicker").change(function() {
if ($(".datepicker").val())
$("#submitButton").removeAttr("disabled");
else
$("#submitButton").attr("disabled", "disabled");
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="submitButton" type="submit" value="blah"
class="btn btn-default" />
<input type="text" class="datepicker">
Upvotes: 2