Skip to content

Instantly share code, notes, and snippets.

@yckart
Forked from 140bytes/LICENSE.txt
Last active October 10, 2015 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yckart/3729385 to your computer and use it in GitHub Desktop.
Save yckart/3729385 to your computer and use it in GitHub Desktop.
previewR: Shows what you type in an input-field or in a textarea.
function(
a, // An input element (textarea, input)
b, // The element to hold the output
c // content-placeholder
) {
c = // Put everything in a variable for a valid returning
b.innerHTML = // Write in the given element
a.value // Get the current content from input element
.replace(/\n/g, '<br>'); // Replace linebreaks
return c; // Return the replaced content
}
function(a,b,c){c=b.innerHTML=a.value.replace(/\n/g,'<br>');return c}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 Yannick Albert <http://yckart.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "previewR",
"description": "Shows what you type in an input-field or in a textarea.",
"keywords": [
"textarea",
"input",
"preview"
]
}
<!DOCTYPE html>
<title>previewR: Shows what you type in an input-field or in a textarea.</title>
<div>Expected value: <b>A short line of text for a better interpretation.</b></div>
<div>Actual value: <b id="ret"></b></div>
<textarea id="textarea" cols="25" rows="5"></textarea>
<script>
var previewR=function(a,b,c){c=b.innerHTML=a.value.replace(/\n/g,'<br>');return c};
document.onkeyup = function() {
previewR(document.getElementById('textarea'), document.getElementById('ret'))
};
</script>
@atk
Copy link

atk commented Sep 17, 2012

RegExp shorthand:

function(a,b,c){c=b.innerHTML=a.value.replace(/\n/g,"<br>");return c};

I suggest you also translate < to <, because otherwise anyone could insert arbitrary html.

@atk
Copy link

atk commented Sep 17, 2012

github doesn't do so in its comments ;-) I meant you should translate < to &lt;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment