<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
<input placeholder="Enter Your Text" type="text" onkeypress="return AvoidSpace(event);" onblur="this.value=removeSpaces(this.value);">
</form>
/* Not Allow Spcace Type in textbox */
function AvoidSpace(event) {
var k = event ? event.which : window.event.keyCode;
if (k == 32) return false;
}
/* Remove Blank Space Automatically Before, After & middle of String */
function removeSpaces(string) {
return string.split(' ').join('');
}
let input = document.getElementsByName("my_input")[0];
let val = input.value.replace(/s/g, "");
alert(val);