I am creating several jQuery scripts to help validate forms before they are submitted. I have read that it is best to always separate jQuery scripts into a separate file so that you can load the script with wp_enqeue_script
.
However, if I am doing something like this:
jQuery(function()
{
var ButtonSelector = "#submit-button";
jQuery(document).on('click', ButtonSelector, function()
{
var ValidEntry = true;
ClearError('#venue_name');
var name = jQuery("#venue_name").val();
if (name == "")
{
CreateError("#venue_name", "Name is Required");
ValidEntry = false;
}
if (!ValidEntry)
{
jQuery('html, body').animate({scrollTop:0}, 'slow');
}
EnableButton(ButtonSelector);
return false;
});
});
Since this function is only used in the one individual form, would it still make sense to separate it out? If I did separate it, wouldn't that mean that it would load for every single page?