Return to Snippet

Revision: 29757
at August 4, 2010 13:32 by Sullan


Initial Code
<!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,"&quot;")
				.replace(/&/g,'&amp;')
				.replace(/</g,'&lt;')
				.replace(/>/g,'&gt;')
				.replace(/'/g,'&apos;')
				.replace(/(
|[
])/g, "<br />")
				.replace(/183/g,'&middot;')
				//.replace(/
/g,'&lt;br/&gt;')
		);
	});
	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,"&quot;")
				  .replace(/&/g,'&amp;')
				  .replace(/'/g,'&apos;')
			      .replace(/[<>]/g, function (s){ return (s == "<")? "&lt;" :"&gt;"});
		  
	}
	 	
</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>

Initial URL


Initial Description
Parsing Carrage return with br tags

Initial Title
Parsing Carrage return with br tags

Initial Tags
jquery

Initial Language
jQuery