/    Sign up×
Community /Pin to ProfileBookmark

need help dispaying data on page load???

Hi All, i am new to js and have a script which displays hidden divs on after another whilst highlighting a tab at the same time which is working fine ?

however the one let down is that when the page first loads the text area is blank until the timer hits its mark and the first div is shown, my question is how do i get the first div to show at page load???

here is the working code

[CODE]<script type=”text/javascript”>

var timer = window.setInterval(“showNext();”, 4000);
var position = -1;
var array = [“detail_info1”, “detail_info2”, “detail_info3”, “detail_info4”, “detail_info5”, “detail_info6”];
var tabs = [“tab1”, “tab2”, “tab3”, “tab4”, “tab5”, “tab6”];

var currentDisplay = 0;
var currentTab = 0;

function showNext() {

if (position == array.length – 1) {

position = 0;
}
else {

position++;
}

showInfo(position);

}

function showInfo(id) {

currentT = document.getElementById(tabs[currentTab]);
currentD = document.getElementById(array[currentDisplay]);

tab = document.getElementById(tabs[id]);
div = document.getElementById(array[id]);

currentD.style.display = “none”;
currentT.style.background = “white”;

div.style.display = “block”;
tab.style.background = “orange”;

currentDisplay = id;
currentTab = id;
}

function startTimer() {
timer = window.setInterval(“showNext();”, 4000);
}
function stopTimer() {
clearInterval(timer);
}
</script>
[/CODE]

and i tried changing this

[CODE]var timer = window.setInterval(“showNext();”, 4000);
var position = -1;
var array = [“detail_info1”, “detail_info2”, “detail_info3”, “detail_info4”, “detail_info5”, “detail_info6”];
var tabs = [“tab1”, “tab2”, “tab3”, “tab4”, “tab5”, “tab6”];

var currentDisplay = 0;
var currentTab = 0;[/CODE]

to this

[CODE]var position = -1;

var array = [“detail_info1”, “detail_info2”, “detail_info3”, “detail_info4”, “detail_info5”, “detail_info6”];
var tabs = [“tab1”, “tab2”, “tab3”, “tab4”, “tab5”, “tab6”];

var currentDisplay = 0;
var currentTab = 0;

showNext();

var timer = window.setInterval(“showNext();”, 4000);
[/CODE]

but nothing seems to happen?

any ideas
thanks

Luke

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @msd_luke spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...