I have a web project in Asp.net MVC where in many pages, there is drop down list controls. When the value of these drop down list changes, a request to the controller action must be made to refresh some div tags.
To do that, I use the $(document).ready() function of jquery and I create a function like this:
$("#ComboBox").change(function() { /* do something here */ });
$.get('@Url.Action("Action", "Controller")', function (result) {
// TODO: process the results of the server side call
});
The problem is I don't want to create a big javascript file that contains a list of all things that must be done in all pages when the document ready event of jquery occurs.
For example, in one page, I have a combobox that create a request to the action x of the controller x and in another page another combobox that create a request to the action y of the controller y.
I'm not sure if this is a good strategy to create a distinct javascripf file for each of these pages.
What can I do? Create a javascript for each specific document ready function? If I put all the functions in the same document ready function of the same javascript file, what about conflict naming in id and class referred by control with jquery? And if all the functions are in the same javascript, what about page that don't use 90% of the functions in the document ready function.