Reputation: 398
I've got Html.TextBoxFor and submit button. My intention is if text box is empty, the button is hidden. I was trying achieve that by this way:
@Html.TextBoxFor(model => model.Tytul, new { id="tytulTextBox", @class = "tytulTextBoxDodajtresc" })
<script type="text/javascript">
$(document).ready(function () {
var button = document.getElementById("DodajTrescButton");
var myLength = $("#tytulTextBox").val().length;
if (myLength > 0) {
button.style.display = "block";
}
});
</script>
What I'am doing wrong ?. I'am very new in jquery, but it looks like using jquery will be the easiest way to achieve that what i want to do.
Upvotes: 0
Views: 179
Reputation: 5286
I think you're missing the else clause on your if
if (myLength > 0) {
$(button).css("display","block");
}
else{
$(button).css("display","none");
}
Upvotes: 1