troubleshooting Question

Break up a javascript IF THEN statement with HTML

Avatar of MDauphinais1
MDauphinais1 asked on
JavaScriptHTMLPHP
9 Comments4 Solutions1486 ViewsLast Modified:
OK, in PHP you can do something like this:

<?
if (something == 1) {
?>
<table><tr><td><font size="1">Regular HTML goes here </font></td></tr></table>
<?
} else {
?>
<font size="2">More HTML goes here</font>
<? } ?>

Basically, you can break up the PHP code with regular HTML code in between. Can I do the same thing with a javascript IF THEN statement?

I am asking because I use a website system that lets me include HTML templates like this:  %%TEMPLATE:mytemplatefile%%   which automatically inserts the html stored in the "mytemplatefile.html" file. (Not exactly sure what language this is called but it uses CGI).

I am trying to write a javascript code that says this:

<script type="text/javascript">
if (data=1) {
document.write('%%TEMPLATE:mytemplatefile%%');
}
</script>

But the HTML located in the mytemplatefile.html file is causing javascript problems when it comes through. So, if my original question is not possible, where you could break up the javascript like you can with PHP, then how can I phrase the javascript so that I can include this HTML without the HTML causing javascript errors?
ASKER CERTIFIED SOLUTION
snrudda

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 4 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros