When it comes to loading a JavaScript function upon page load, there are various methods such as onLoad(), $( document ).ready(), and more. However, I am facing an issue with a function that does not have a specific name. This unnamed function is used to load a select statement dynamically based on the value selected from another element. The code below works perfectly for this purpose, but I need it to execute both when the page loads initially and when the value of the first select element changes. Despite my efforts in searching for examples, I have been unsuccessful in finding a solution. My usual Google search skills seem to be failing me in this case. Can anyone guide me in the right direction?
$(document).ready(function()
{
$("#nameregion").change(function()
{
var region= document.getElementById("nameregion").value;
$.ajax
({
type: "POST",
url: "namebranch.php",
data: { 'myRegion' : region },
//cache: false,
success: function(data)
{
//alert( data );
$("#namebranchoptions").html(data);
}
});
});
});