/    Sign up×
Community /Pin to ProfileBookmark

AJAX tabs function only works once

Hey,

I’m hoping this is a simple fix, but I have a function that populates the main div on the page according to the tab clicked (a div).

It works great when you click the first tab, but if you go to click anymore after that, it simply doesn’t work.

Here’s the tabs code:

[CODE]<div class=”hovermenu_home” id=”tab1″ onclick=”getTabData(1)”>Tabloids</div>
<div class=”hovermenu_home” id=”tab2″ onclick=”getTabData(2)”>Blurbs</div>
<div class=”hovermenu_home” id=”tab3″ onclick=”getTabData(3)”>Charts</div>
<div class=”hovermenu_home” id=”tab4″>Stars</div>[/CODE]

And here’s the Javascript, which resides at the bottom of the page:

[CODE]function getTabData(id) {
if (id == 2) {
var url = ‘../core3/feeds/blurbFeed.php’; }
else if (id == 3) {
var url = ‘../core3/feeds/test.php’; }
else if (id == 4) {
var url = ‘../core3/feeds/tabloid_feed.php’; }
else {
var url = ‘../core3/feeds/tabloid_feed.php’; }

var rand = Math.random(9999);
var pars = ‘id=’ + id + ‘&rand=’ + rand;
var myAjax = new Ajax.Request( url, {method: ‘get’, parameters: pars, onLoading: showLoad, onComplete: showResponse} );
}
function showLoad () {
$(‘load’).style.display = ‘block’;
}
function showResponse (originalRequest) {
var newData = originalRequest.responseText;
$(‘load’).style.display = ‘none’;
$(‘feed_main’).innerHTML = newData;
}[/CODE]

Any ideas? I just started learning JavaScript coming from a strong HTML/CSS/PHP background and I just don’t have any major flaw jumping out at me.

Thanks in advance!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @ckts 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.17,
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,
)...