Solved

Javascript html dynamic rendering

Posted on 2014-10-03
3
129 Views
Last Modified: 2014-10-03
What's the best way to render the below(buildTargetTable()) to the browser?  I'm trying to build a table on the fly as the page is getting rendered.

The below works but only if I alert it or console.log it.  What I want to do is make it render to the browser.

<!DOCTYPE html>

	<script LANGUAGE="JavaScript">

function buildTargetTable(tblType)
{
	var tbl = "";
	
	tbl = "<Table id="+tblType+"></Table>";
	return tbl;
}

buildTargetTable("PBC");

buildTargetTable("Sample");

buildTargetTable("Whatever");

</script>

Open in new window


Any ideas?

Thanks!
0
Comment
Question by:Isaac
[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
3 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40360261
document.write (buildTargetTable("PBC"));

document.write (buildTargetTable("Sample"));

document.write (buildTargetTable("Whatever"));

Open in new window

0
 
LVL 5

Author Comment

by:Isaac
ID: 40360263
i tried that before asking for help but it did not work.

Also, isn't there a downside to using document.write
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40360268
Well you won't see anything in the browser just using
tbl = "<Table id="+tblType+"></Table>";
as the tables don't contain anything, you need at least one row and one cell
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

737 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