Solution:
First, try echoing the script in the wp_head to see if you can get it to work. If that works, it’s likely that you have an issue with your file path in your wp_enqueue.
So try this, then load the page and see if it works. You should not add JS to your site this way generally, but is effective in testing. Enqueuing is the proper way to add scripts and styles, but in order to determine that it’s not the JS, and is something else, you should try this.
function loginscript() {
echo "
<script>
function changeQuery(){
var input_query = document.getElementById('token').value;
window.location = 'https://www.example.com/' + input_query;
</script> ";
}
}
add_action('wp_head','loginscript');
If the functionality works this way, then check your file path. It might be easier to just use the full relative file path rather than using wordpress built in file path functions. So for example, if you js file has a path of /wp-content/themes/my-theme/js/loginscript.js, you could do an enqueue like so:
wp_enqueue_script('loginscript', '/wp-content/themes/theme_name/js/loginscript.js');