/ Published in: jQuery
Parsing Carrage return with br tags
Expand |
Embed | Plain Text
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>jQuery Parsers</title> <script type="text/javascript" src="../../jquery-1.3.2.min.js"></script> <script type="text/javascript"> // JavaScript Document jQuery(function($) { $('p.solutionNotes').escapeHtml(); var notesText = $('p.solutionNotes').text(); alert(notesText); $('.sNotes').html(notesText); $('#submit').click(function() { var htmlval = $('#textEntry').val(); $('p.escape').text(htmlval); $('p.escape').escapeHtml(); var parsedText = $('p.escape').text(); //alert(parsedText); $('#finalVal').val(parsedText); var final = $('#finalVal').val(); //alert(final); }); }); (function($) { ; $.fn.escapeHtml = function() { this.each(function() { $(this).html( $(this).html() .replace(/"/g,""") .replace(/&/g,'&') .replace(/</g,'<') .replace(/>/g,'>') .replace(/'/g,''') .replace(/( |[ ])/g, "<br />") .replace(/183/g,'·') //.replace(/ /g,'<br/>') ); }); return $(this); } })(jQuery); </script> </head> <body> <script type="text/javascript"> jQuery(function($) { var textTextarea = $('.escape').html(); //alert(textTextarea); //$('#textEntry').val(textTextarea); }); function parseStrings(obj){ var data = obj.form.textEntry.value; obj.form.finalVal.value = carrageReturn(data); } function carrageReturn(dataStr) { return dataStr.replace(/( |[ ])/g, "<br />") .replace(/"/g,""") .replace(/&/g,'&') .replace(/'/g,''') .replace(/[<>]/g, function (s){ return (s == "<")? "<" :">"}); } </script> <p class="escape"><big>asdfasd</big></p> <br /> <FORM id=crlf2br name=crlf2br action="test.html"> <TEXTAREA class=textarea id="textEntry" name="textEntry" rows=5 cols=75>Insert line breaks into this string by pressing enter with the cursor between the words.</TEXTAREA> <INPUT onclick='parseStrings(this)'; type="button" value="Convert to Tag"> <TEXTAREA class="textarea readonly" id="finalVal" name="finalVal "rows=5 readOnly cols=75></TEXTAREA> </FORM> <p class="solutionNotes"></p> <p class="sNotes">sdf</p> </body> </html>
Comments
Subscribe to comments
You need to login to post a comment.

just because we love christian louboutin,also we think it will made you be more sexy.IN christian louboutin sale,you can get your luxury christian louboutin shoes at cheap price.christian louboutin shoes(born 1964) is a footwear designer who launched his line of high-end women's shoes in France in 1991.trademark protection of this red sole design.cheap christian louboutin shoes,louboutin shoes,christian louboutin shoes on sale,christian louboutin sale,cheap ugg boots,ugg boots saleugg classic tall and ugg classic cardy,ugg classic short,cheap christian louboutin,christian louboutin pumps,cheap christian louboutin