html - Textarea - JavaScript | Remove line breaks and spaces from content field -
<textarea rows='5' cols='50' id='content'></textarea> <input type='button' value='extract text' onclick='somefunction()'/>
assume these 2 html elements. problem following:
let's user enters textarea field this, typed. line breaks , spaces. (and yes, python :p)
if (...): print "hello everyone!" else: print "dudes me out!"
my objective make javascript function removes spaces , line breaks (typed 'enter') , returns space-less string. "thisisasampletext". i've used document.getelementbyid('content').value
, mystring.replace(/\s+/g, '')
remove spaces. can't make work. ideas?
best regards
here's live demo of how use regex described remove whitespace in text textarea:
function somefunction() { var output = document.getelementbyid("content").value; output = output.replace(/\s/g, "") document.getelementbyid("output").innerhtml = output; }
<textarea rows='5' cols='50' id='content'></textarea> <input type='button' value='extract text' onclick='somefunction()'/> <div id="output"></div>
jsfiddle version: https://jsfiddle.net/afy5v66x/1/
Comments
Post a Comment