Solved

how to read htmlusing javascript

Posted on 2011-09-29
4
236 Views
Last Modified: 2012-05-12
Hi,
  I am creating a table using javascript. I have the attached text coming from database. I wanted to show that text in table. if I use cratetextnode, it is displaying all html tags. How can I display the data in html format using javascript.

Please let me know if this is not clear.

Thank  you
<DIV class=Section1>  <P><SPAN style="COLOR: black">PROCEDURE:&nbsp; test</SPAN><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></P>  <P><SPAN style="source-type: 1" source="D"><SPAN style="COLOR: black">INDICATION:&nbsp; <SPAN style="source-type: 1" source="D"></SPAN>testtesteststst</DIV>

Open in new window

0
Comment
Question by:Sthokala
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Eyal
ID: 36817685
with JQuery it's strait forward

$("#ELEMNTID").html(the html from your database);
0
 

Author Comment

by:Sthokala
ID: 36817727
Hi,
  Please find my code for creating a table using javascript. The html string I  wanted to convert is this.
data[6] contains a html string that I shown above. I am fine with using Jquery also, but not sure how to use it in below situation
col.appendChild(document.createTextNode(data[6]));

Thank you
function getInterpretation(tr){
	var examID = ReplaceSpaces(tr.getElementsByTagName("input")[1].value);
	var repTable =document.getElementById("reportTbl");
	var lastRow = repTable.rows.length-1,  i;
	  for (i = lastRow; i >= 0; i--) {
		  repTable.deleteRow(i);
	}
	if(examID!="null"){
	var xmlhttp = getxmlHttpRequest();
	var strURL = "getTest.jsp?examID="+examID+"&unique="+'<%=Math.random()%>';
	xmlhttp.open("GET", strURL,true);
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	  {
		
			var responseText = xmlhttp.responseText.split("<br>");
			
			for(var i=0;i<responseText.length-1;i++) {
			
			var data = responseText[i].split("<td>");
			var data = responseText[i].split("<td>");
			
			var tblBody = document.createElement("tbody");
			var row = document.createElement("tr");
						
			var cell = document.createElement("td");
			var patientName = document.createTextNode("Patient Name: "+data[2]);
		
			cell.appendChild(patientName);
			cell.style.cssText="font-weight:bold;";
			row.appendChild(cell);
			tblBody.appendChild(row);
			var row = document.createElement("tr");
		  	var col = document.createElement("td");
		  	col.appendChild(document.createTextNode("Exam  :"+data[1]));
			col.style.cssText="font-weight:bold;";
			row.appendChild(col);
			tblBody.appendChild(row);
			var row = document.createElement("tr");
		  	var col = document.createElement("td");
		  	col.appendChild(document.createTextNode("Exam Date  :"+data[0]));
			col.style.cssText="font-weight:bold;";
			row.appendChild(col);
			tblBody.appendChild(row);
			var row = document.createElement("tr");
		  	var col = document.createElement("td");
		  	col.appendChild(document.createTextNode("Signed Date  :"+data[3]));
			col.style.cssText="font-weight:bold;";
			row.appendChild(col);
			tblBody.appendChild(row);
			var row = document.createElement("tr");
		  	var col = document.createElement("td");
		  	col.appendChild(document.createTextNode("Reading Radiologist  :"+data[4]));
			col.style.cssText="font-weight:bold;";
			row.appendChild(col);
			tblBody.appendChild(row);
			var row = document.createElement("tr");
		  	var col = document.createElement("td");
		  	col.appendChild(document.createTextNode("Signing Radiologist  :"+data[5]));
			col.style.cssText="font-weight:bold;";
			row.appendChild(col);
			tblBody.appendChild(row);
			var row = document.createElement("tr");
		  	var col = document.createElement("td");
		  	col.appendChild(document.createTextNode("Interpretation   :"));
			col.style.cssText="font-weight:bold;";
			row.appendChild(col);
			tblBody.appendChild(row);
			var row = document.createElement("tr");
		  	var col = document.createElement("td");
			col.appendChild(document.createTextNode(data[6]));
			col.setAttribute("colSpan", "2");
			row.appendChild(col);
			
			tblBody.appendChild(row);
			
			repTable.appendChild(tblBody);
		}
	  }
	}
	xmlhttp.send();
	}
}

Open in new window

0
 
LVL 15

Accepted Solution

by:
Eyal earned 500 total points
ID: 36817798
first pay attention that you do the split twice with no reason


var row = document.createElement("tr");
                    var col = document.createElement("td");
                                    col.setAttribute("id", "col6");
                  col.setAttribute("colSpan", "2");
                  row.appendChild(col);
                  
                  tblBody.appendChild(row);

$('#col6').html(data[6]));
0
 

Author Comment

by:Sthokala
ID: 36817837
Thank you . That worked exactly as I wanted.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question