Submit form when contents of MVC3 Html.TextBoxFor changes?

If you're willing to use JQuery, it's very simple to do.

Up vote 0 down vote favorite share g+ share fb share tw.

This should be fairly easy but I've tried a few things with no luck. I have a series of Html. TextBoxFor fields on a page, each inside their own Ajax.BeginRouteForm.

Next to each box I have a submit button, and this, when clicked, performs the Ajax update as desired. I'd like to automate this so that when the user changes a value in a field (the onchange event) the form is submitted the same way it currently using using the submit button. I tried using the htmlattributes to assign a javascript function to the onchange event (as shown below) and this causes the form to submit, but it redirects the page instead of working in the ajax fashion (as opposed to clicking the submit button which works correctly).

@(Html. TextBoxFor(model => answer. Value, new { onchange = "document.

Forms" + answer. AnswerID + ".submit()" })); (fortunately my answer. AnswerID is numeric and matches up with the numeric position of the appropriate form in the forms collection; I was referencing them by name but Razor (or something) was htmlencoding my javascript code...) My only guess is that I'm breaking something by attaching code directly to the onchange event, but I'm at a loss as to the "right" way to hook into that event chain.

Mvc asp. Net-mvc-3 asp. Net-ajax razor link|improve this question asked Jul 28 '11 at 17:13jasongullickson1498 71% accept rate.

If you're willing to use JQuery, it's very simple to do: net.tutsplus.com/tutorials/javascript-aj....

Please feel free to elaborate :) – jasongullickson Jul 29 '11 at 19:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions