Solved

how to read htmlusing javascript

Posted on 2011-09-29
4
234 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now