0

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).

tereško
  • 56,151
  • 24
  • 92
  • 147
GrahamHull
  • 325
  • 1
  • 3
  • 12
  • Is jQuery accepted? If so, you can add a listener on the targeted textbox and, say, on `enter` just call the `submit` on that form. – Andrei V Mar 21 '14 at 09:59
  • jQuery is completely fine, although im a complete beginner with it! – GrahamHull Mar 21 '14 at 10:01
  • [This question](http://stackoverflow.com/questions/699065/submitting-a-form-on-enter-with-jquery) has what you need. Just change the selector (".input") to the id of your text box. Maybe [this one](http://stackoverflow.com/questions/8981637/submit-form-with-enter-key) will help as well. – Andrei V Mar 21 '14 at 10:03

1 Answers1

2

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.

dav_i
  • 25,285
  • 17
  • 94
  • 128