How to make JavaScript block the 'space key' inside a textbox
<p>First of all, I've already tried <a href="https://stackoverflow.com/questions/18780304/javascript-disable-space-key-for-change-password-textboxes">this solution</a> and it doesn't work for me, unless I put the script in the HTML page (I didn't do it because I've a page for all the scripts). Another solution that does work but that I haven't understand is this:</p>

<pre><code>&lt;input type="password" id="pwd" required pattern=".{8,16}" title="8 characters minimun, 16 characters maximum" name="fpwd" placeholder="Password" size = "13" onkeypress="return (event.keyCode != 32&amp;&amp;event.which!=32)&gt;
</code></pre>

<p>So, the question is: why the first solution works only if the script is in the HTML page?</p>