Skip to content
Advertisement

Passing string to Bootstrap Modal using Javascript

Learning Javascript and trying to learn how to pass values. In this example, I have a where a user types a message, for example, and that string is stored and displayed in a Bootstrap Modal. The problem…the last character is cut off unless you press return or spacebar. I have tried adding an empty space at the end of my document.getElementById (line 38)…tried adding a carriage return and new line….I have found several very simple Jquery solutions but it would be nice if I could figure this one out using JS first. Or maybe I should just switch the script to JQuery? I also know my character count isn’t working correctly but I’ll figure that out later.

Thanks!

JavaScript
JavaScript

Advertisement

Answer

According to MDN (https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onkeypress), the onkeypress event handler has been deprecated.

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes

So, in order to avoid the cut of the last character, you can use the onkeyup event handler, which fires when the user releases a key that was previously pressed.

JavaScript

Fiddle: https://jsfiddle.net/kongallis/e087vdgL/12/

Advertisement