3 examples of 'how to get input from user in javascript' in JavaScript

Every line of 'how to get input from user in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
186function runInput(){
187 var scr = editor.getValue();
188 csInterface.evalScript("$.runScriptFromInput("+$.stringify(scr)+")");
189}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

29function input(html_id) {
30 // emulate MATLAB's user-input: use the original (or hacked)
31 // prompt as selection into DOM by id and return the content. We
32 // could change this to a pop-up later.
33 // WARN: We're ignoring the second element, which always seems to be a 's' for string.
34 var elem = document.getElementById(html_id);
35 if (elem.tagName === "INPUT") {
36 return document.getElementById(html_id).value;
37 } else { // e.g., "TEXTAREA"
38 return elem.textContent;
39 }
40}
1690function processInput (input, code) {
1691 var data, dataArr, i, c, len;
1692
1693 switch (typeof input) {
1694 case 'string':
1695 data = input;
1696 break;
1697 case 'number':
1698 data = input.toString();
1699 break;
1700 case 'object':
1701 if (input.constructor === window[___JSQR___].prototype.Input) {
1702 data = input.toString();
1703 } else if ((Array.isArray || function(o) { return Object.prototype.toString.call(o) === '[object Array]'; })(input)) {
1704 return input;
1705 } else {
1706 data = (new window[___JSQR___].prototype.Input(input.dataType, input.data)).toString();
1707 }
1708 break;
1709 default:
1710 throw new TypeError('Unsupported input parameter');
1711 }
1712
1713 dataArr = (code.encodeMode === code.ENCODE_MODE.UTF8_SIGNATURE ? [0xef, 0xbb , 0xbf] : []);
1714
1715 if (code.encodeMode === code.ENCODE_MODE.UTF8_SIGNATURE || code.encodeMode === code.ENCODE_MODE.UTF8) {
1716 // UTF-8 Encode
1717 for (i = 0, len = data.length; i < len; i++) {
1718 c = data.charCodeAt(i);
1719 if (c < 128) {
1720 dataArr.push(c);
1721 } else if((c > 127) && (c < 2048)) {
1722 dataArr.push((c >> 6) | 192, (c & 63) | 128);
1723 } else {
1724 dataArr.push((c >> 12) | 224, ((c >> 6) & 63) | 128, (c & 63) | 128);
1725 }
1726 }
1727 } else {
1728 for (i = 0, len = data.length; i < len; i++) {
1729 dataArr.push(data.charCodeAt(i));
1730 }
1731 }
1732
1733 return dataArr;
1734}

Related snippets