If I know that when a certain condition is true, I'll need to run different scripts, is it possible to load the script dynamically into a function I'm running?
$("#container").on("click", "#submit", function(){
var prodID = $("#productSelect").find(".selected_option").data("product_id");
//somehow load a script like "validation_" + prodId;
});
Or should I manually put all the code into a single function
$("#container").on("click", "#submit", function(){
var prodID = $("#productSelect").find(".selected_option").data("product_id");
switch (prodID){
case 1:
//code for prodID 1
break;
case 2:
//code for prodID 2
break;
case 3:
//code for prodID 3
break;
}
});
It is just an attempt to keep things a little cleaner looking. I don't know if it's a good idea. Thanks.