Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to read htmlusing javascript

Posted on 2011-09-29
4
Medium Priority
?
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 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