Solved

how to read htmlusing javascript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

911 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

20 Experts available now in Live!

Get 1:1 Help Now