P_KAM
P_KAM

Reputation: 3

Data being overwritten in this one specific scenario

I'm new to JS and HTML and there are many things I'm trying to understand so if anyone can help and explain it'd be great.

Here's my snippet.

<script>
$(".radio-inline").click(function(){
 $("#team").click(function(){
    create_Countdown(data[2].year, data[2].month, data[2].day, data[2].Hours, data[2].ampm, data[2].minute, data[2].second); 
   });
});
</script>

For some reason whenever I call the create_Countdown() function within the jquery functions it is generated on an all blank page. I am assume that all the other code is being deleted for some reason. The weird thing is that if I call the function without call the jquery function it prints where I want it to.

Can anyone help?

For those asking to see the code for create_Countdown() here it is

function create_Countdown(yearx, monthx, dayx, hourx, ampmx, minutex, secondx){ //Code to create a new countdown with the parameters
    new Countdown({year  : yearx, 
    month : monthx, 
    day   : dayx, 
    hour  : hourx,
    ampm  : ampmx,
    minute  : minutex, 
    second  : secondx});

}

I tried to put a return before new to see if there would be a difference and nope.

Upvotes: 0

Views: 50

Answers (2)

AJ Richardson
AJ Richardson

Reputation: 6830

I figured it out by looking at their "Advanced Options" example. Basically, you need to specify a target where the Countdown will be created (otherwise it seems to use document.write or something that messes up your html).

First you need this somewhere in your html:

<div id="countdown"></div>

Then, in your javascript:

function create_Countdown(yearx, monthx, dayx, hourx, ampmx, minutex, secondx) {
    new Countdown({
        year   : yearx, 
        month  : monthx, 
        day    : dayx, 
        hour   : hourx,
        ampm   : ampmx,
        minute : minutex, 
        second : secondx,
        target : "countdown" // A reference to an html DIV id
    });
}

This tells Countdown to create itself inside of an existing HTML element instead of its default behavior.

You can see it in action here: http://jsfiddle.net/gnhtb1cp/5/

Upvotes: 0

Scott Selby
Scott Selby

Reputation: 9580

why are there click handlers nested inside of each other?

$(".radio-inline").click(function(){
   // when I click .radio-inline
   // then attach click handler to #team element
   $("#team").click(function(){
      //then when I click #team , after I have click radio-inline
      //then create count_countdown
        create_Countdown(data[2].year, data[2].month, data[2].day, data[2].Hours, data[2].ampm, data[2].minute, data[2].second); 
   });
});

Upvotes: 1

Related Questions