Search code examples
javascriptjqueryadvertisement-server

This code doesn't seem to fire this button. What's going wrong?


I'm working on something for a client and an agency have built a small bit of jQuery to fire off a DoubleClick Floodlight Tag but for some reason the tag doesn't work:

<script type="text/javascript">
$(function () {

    //var origOnClick = $('#trackingButton').attr("onclick");
    $('#trackingButton').click(fireFloodlight);
    function fireFloodlight() {
        if (Page_IsValid) {
            var axel = Math.random() + "";
            var a = axel * 10000000000000;
            $("body").append('<img src="https://ad.doubleclick.net/activity;src=2499215;type=axa_l124;cat=lpg_g263;ord=' + a + '?" width="1" height="1" alt=""/>');
            //eval(origOnClick);
        }
    }

});
</script>

To me this script looks fine, but in a live environment the call to "ad.doubleclick.net" is never made? Any help would be much appreciated. Strangely the tag was working until this weekend but now is not recording any actions?

EDIT: I did a console.log(Page_IsValid) which returned True.

EDIT: Here is the HTML for the button in question:

<input type="submit" name="ctl00$ctl00$ctl00$BodyPlaceHolder$BodyPlaceHolder$WizardContentPlaceHolder$WizardCollectBasicSMEInfo$trackingButton" value="Get your quick quote" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl00$ctl00$BodyPlaceHolder$BodyPlaceHolder$WizardContentPlaceHolder$WizardCollectBasicSMEInfo$trackingButton&quot;, &quot;&quot;, true, &quot;Form&quot;, &quot;&quot;, false, false))" id="trackingButton" class="button" />

Solution

  • You already have the function on document ready, your problem is that you are calling the function in a wrong way, if you want to call the function like that you should declare it as a function expression (see Function Expressions in this link for more info):

    $(function () {
    
    var fireFloodlight = function()  {
        if (true) {
            var axel = Math.random() + "";
            var a = axel * 10000000000000;
            $("body").append('<img src="http://tejedoresdesuenos.com.mx/wp-content/uploads/2011/06/google.jpg" width="50" height="10" alt=""/>');
            alert('ello');
        }
    }
    
    $('#trackingButton').click(fireFloodlight);
    
    
    });
    

    a working example.