Reputation: 325
So I have a requirement to auto submit a form upon edit of a set textbox within a form.
using (Ajax.BeginForm(new AjaxOptions() { UpdateTargetId = "refresh", InsertionMode = InsertionMode.Replace }, new { @id = "refresh" }))
{
@Html.ValidationSummary();
@Html.TextBoxFor(modelitem => Model.Requirement)
}
How can I make that form submit to the controller method upon edit of the textbox? (if possible).
Upvotes: 0
Views: 5413
Reputation: 28107
I think the jQuery solution this should work like this:
<script type="text/javascript">
$('#Requirement').change(function () {
$('#refresh').submit();
});
</script>
The above will run when the text box loses focus (and had changed value), if you want to do it on every keypress you can replace change
for keyup
or keydown
as you see fit.
Upvotes: 2