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

3
  • 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. Commented Mar 21, 2014 at 9:59
  • jQuery is completely fine, although im a complete beginner with it! Commented Mar 21, 2014 at 10:01
  • This question has what you need. Just change the selector (".input") to the id of your text box. Maybe this one will help as well. Commented Mar 21, 2014 at 10:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.