Textarea in the paragraph or plain text
source link: https://www.codesd.com/item/textarea-in-the-paragraph-or-plain-text.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Textarea in the paragraph or plain text
I have a form where a user is able to comment via a textarea. If the submit button is clicked it returns the value of what is entered in the textarea inside a textarea. How can I change this it so that on submit the value of the textarea is returned as a plain text/paragraph with jquery or php?
The code for textarea and button:
<textarea rows="6" cols="40" scroll="auto" name="reply_for_{$item.id}">
{if isset($item.reply)}
{$item.reply}
{/if}
</textarea>
<br />
<input name="addcomment" value="{lang mkey='submit'}" type="button" onclick="
document.forms['commentsFrm'].id.value={$item.id};
document.forms['commentsFrm'].submit();
"/>
$('input[name="addcomment"]').on('click',function(){
var comment = $('textarea').val();
$('textarea').remove(); // removes the textarea
var actContent = $(this).parent().html(); // get the actual content of the parent dom node.
$(this).parent.html('<p>'+comment+'</p>'+actContent); // you set the new html content for the parent dom node
});
So this would take the textarea content and save it into a paragraph. A bit akward solution but it should do the magic.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK