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
Solved

how to read htmlusing javascript

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

828 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