0

i created a form using asp.net mvc, i am using entity framework database.on the form there are text fields, how do i add javascript inside a html helper.

bellow is the textfield

@Html.TextAreaFor(m => m.ShortSummary, htmlAttributes: new { onkeyup = UpdateLength(600, "ShortSummary", "count" ) })
<span id="count"></span>

bellow its the function i created to count the number of characters when the user types

<script type="text/javascript">
    function UpdateLength(length, textID, spanID) {
        var text = document.getElementById(textID);
        var span = document.getElementById(spanID);

        span.innerHTML = (length - text.value.length);
    }
</script>

i want to add the above function to the text field

1 Answers1

0

this code worked fine for me, thanks for all the help <textarea asp-for="ShortSummary" class = "form-control resizer" placeholder = "Short Summary (90 words)" tabindex = 1 rows = 8 onkeyup='UpdateLength(600, "ShortSummary", "count")'></textarea>