<script>
    function printAndTerminate(str) {
        window.print(str);
        window.terminate();
    }

    function printValue(id) {
        printAndTerminate(document.getElementById(id).value);
    }

    function printOnEnter(event) {
        /* Number 13 is the "Enter" key on the keyboard */
        if (event.keyCode === 13) {
            event.preventDefault();
            printValue(this.id);
        }
    }
</script>
