The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> HTML | Javascript | -- Importing / dislpaying HTML inside Javascript
sanoj96
post Jan 24 2019, 06:10 PM
Post #1


Advanced Member
****

Group: Members
Posts: 107
Joined: 18-September 12
Member No.: 17,803



Hello,


So i am having a litle project.

So my quesstion is what is the best way to use HTML inside a javascript ? as of now i am using this

CODE
            info: '<div class="info_content">\n' +
            '<h3><?php echo $locations[$i]['address'];?></h3>\n' +
            '<div class="slideshow-container">\n' +
            '<div class="mySlides fade">\n' +
            '<img src="https://urbanhus.no/wp-content/uploads/U-1030_cam01_day_snow-1600x1160.jpg" style="width:100%">\n' +
            '</div>\n' +
            '<div class="mySlides fade">' +
            '<img src="https://urbanhus.no/wp-content/uploads/U-940_cam02_day-1-1600x900.jpg" style="width:100%">\n' +
            '<div class="text">Caption Two</div>\n' +
            '</div>\n' +
            '<div class="mySlides fade">\n' +
            '<img src="https://urbanhus.no/wp-content/uploads/U-1090_cam01_dusk_snow-768x576.jpg" style="width:100%">\n' +
            '<div class="text">Caption Three</div>\n' +
            '</div>\n' +
            '<a class="prev" onclick="plusSlides(-1)">❮</a>\n' +
            '<a class="next" onclick="plusSlides(1)">❯</a>\n' +
            '</div>\n' +
            '<br>\n' +
            '<div style="text-align:center">\n' +
            '<span class="dot" onclick="currentSlide(1)"></span>\n' +
            '<span class="dot" onclick="currentSlide(2)"></span> \n' +
            '<span class="dot" onclick="currentSlide(3)"></span> \n' +
            '</div>\n',


But this takes time and makes the code unclear / hard to read.
So my quesstion is what do you guys reccommend? have it in it own file and imprt that file ?

NOTE: The HTML will have PHP inside at a later time.

Also when i did this, this happend:

IPB Image

When it is supposed to look like this:

IPB Image
(it gets like this when i click on one of the dots)

Made the slide show in one file, and then imported it like shown above.

Thanks in advanced,

(Sorry for bad english, feel free to ask quesstions if you didnt understand)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Christian J
post Jan 27 2019, 12:15 PM
Post #2


.
********

Group: WDG Moderators
Posts: 8,206
Joined: 10-August 06
Member No.: 7



Why do you put the HTML code in the locations variable in the first place? Why not use static HTML (created by PHP if necessary)?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 23rd August 2019 - 09:12 AM