There many approach for your js part on input, and you were correct, but we can’t disccuss a lot about it here. And a part for your question related to WordPress, yes you are right. You can use wp_enqueue_scripts
to enqueue your js function inside js file, remember to use get_stylesheet_directory_uri
as part url of your js file since you are in child theme, and set to in footer ( take your time to search for example code here, a lot! ).
But for a pieces code, I would like just fire wp_footer
, take a look @EAMann answer.
Your code may like this ( put in functions.php
theme file ):
add_action( 'wp_footer', 'wpse222047_script_footer' );
function wpse222047_script_footer() {
?>
<script type="text/javascript">
if ( undefined !== window.jQuery ){
function SaveShopID($ShopID){
jQuery("#order_comments").val($ShopID);
}
}
</script>
<?php
}
I hope this helps.