Jquery: How Can I Add Line Break To Form Input?
I'm collecting information in a standard HTML form. I have, for example, . When the form is submitted, I want to add a line brea
Solution 1:
I posted my previous answer before I saw your comment that the output is plain text. Now try this:
$(document).ready(function() {
$("#formID").submit(function () {
$(":text").each(function () {
var value = $(this).val();
var myname = $(this).attr('name');
var newValue = value + " \n";
var hid = '<input type="hidden" name="' + myname + '" value="' + newValue + '"/>';
$(this).removeAttr('name');
$("#formID").append(hid);
});
});
});
Previous Answer
As Mark says, the line break character is not rendered as a line break when viewed in the browser (or email client for that matter), so instead of adding a line break character "\n", you should add a <br/>
$("#formID").submit(function () {
$(":text").each(function () {
var value = $(this).val();
var newValue = value + '<br/>';
$(this).val(newValue);
});
})
Post a Comment for "Jquery: How Can I Add Line Break To Form Input?"