I would like an HTML form that has a few fixed inputs, as well as some dynamic ones that are selected based on an a drop-down. My goals:
- I would prefer this is entirely handled in the browser, rather than AJAX calls to fetch the dynamic “sub-form” portions that were selected by the drop-down.
- Rather than adding a 3rd party JS library, I would like to leverage the libraries that come with ASP.NET MVC4 (jquery, knockout, etc.). However, I am willing to add a 3rd party library if the former attempt is too clumsy.
What path do you recommend? Does HTML5 have any “help” for this?
Update
It occurs to me that the HttpPost of the form should not include “sub-form” values that were not chosen in the select box. What now? Store the extra div elements in an out-of-document list and swap them in as needed? Or perhaps much better, have an event attached to the submit button that deletes the unused/invisible divs before posting?
Pure javascript is perfectly capable of this. jQuery will make your life a bit easier should you go that route.
Here’s an example of how to show different form options based on a dropdown value using jQuery:
Fiddle: http://jsfiddle.net/RDtVZ/