html - How to insert <p> tag in textfield when user hits "Enter" or "Return"? -
in app, user can fill out information him on profile. example have section, user can write paragraph life. right now, if user types , saves input, shown 1 paragraph. want if user hits enter, should add <p>
tag when displaying content.
update
just @ question example. when type question , hit enter
this text appeared on new line
this want!
you dont have handle enter key.
lets assume getting textarea value string str
.
when display it, wrap every line <p>
//`str` textarea value var str = document.getelementbyid("mytextarea").value; var lines = str.split(/\r?\n/); // create html var html=""; for(var i=0;i<lines.length;i++){ html+='<p>'+lines[i]+'</p>'; } // use html here showing inside div var divel = document.getelementbyid("mydiv"); divel.innerhtml = html;
Comments
Post a Comment