Solved

Insert HTML DIV in Javascript

Posted on 2014-09-29
5
188 Views
Last Modified: 2014-09-30
I need to insert two divs in this javascript code but not sure how.

I would like to insert after the beggining of the script tag:

<div class="infobox-wrapper">
<div id="infobox">


And at the end:
</div></div>



<script type="text/javascript">
var poiAddress = " <?php echo $attorneysStuff['bizAddr'];?>, <?php echo $bizCity;?>, <?php echo $bizState;?>";
var poiHTML = ' <?php echo $attorneysStuff['bizName'];?><br><?php echo $attorneysStuff['bizAddr'];?>, <?php echo $attorneysStuff['bizCity'];?><br><?php echo $attorneysStuff['bizState'];?><br>Phone:<?php echo $attorneysStuff['bizPhone'];?>';
var poiZoomLevel = 12;
var infoHTML = "";

</script>

Open in new window

0
Comment
Question by:seopti
  • 2
  • 2
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40350849
I think you're looking for document.write : https://developer.mozilla.org/en-US/docs/Web/API/document.write

But, today, it's not the right way to do that, it's a bit old school :)) IMHO
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40350984
If you actually mean to put them inside the script tags like below, that won't work right.  The <div>s won't be recognized and will cause errors in the javascript.
<script type="text/javascript">
<div class="infobox-wrapper">
<div id="infobox">
var poiAddress = " <?php echo $attorneysStuff['bizAddr'];?>, <?php echo $bizCity;?>, <?php echo $bizState;?>";
var poiHTML = ' <?php echo $attorneysStuff['bizName'];?><br><?php echo $attorneysStuff['bizAddr'];?>, <?php echo $attorneysStuff['bizCity'];?><br><?php echo $attorneysStuff['bizState'];?><br>Phone:<?php echo $attorneysStuff['bizPhone'];?>';
var poiZoomLevel = 12;
var infoHTML = "";
</div></div>
</script>

Open in new window

0
 

Author Comment

by:seopti
ID: 40351256
Dave, well that's the reason I'm posting here :)
0
 

Author Comment

by:seopti
ID: 40351258
Javascript is a dumb programming language, not even simple DIVS are possible. I don't know who invented this shitty language.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40351283
In this scenario the script tag is INSIDE the BODY tag :
<body>
<script type="text/javascript">
document.write('<div class="infobox-wrapper">');
document.write('<div id="infobox">');
document.write('<?php echo $attorneysStuff['bizAddr'];?>, <?php echo $bizCity;?>, <?php echo $bizState;?>');
document.write('<?php echo $attorneysStuff['bizName'];?><br><?php echo $attorneysStuff['bizAddr'];?>, <?php echo $attorneysStuff['bizCity'];?><br><?php echo $attorneysStuff['bizState'];?><br>Phone:<?php echo $attorneysStuff['bizPhone'];?>');
var poiZoomLevel = 12;
var infoHTML = "";
document.write('</div></div>');
</script>

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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 …
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…

705 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

19 Experts available now in Live!

Get 1:1 Help Now