javascriptcaptchaaddthis

How can i fix error in captcha included addthis


I create captcha with javascript. here my code :


    var a = Math.ceil(Math.random() * 10);
    var b = Math.ceil(Math.random() * 10);
    var c = Math.ceil(Math.random() * 10);       
    var d = a + b + c;
    function DrawBotBoot(){
        document.write("What is "+ a + " + " + b + " + " + c +" ? ");
    }    

    function ValidBotBoot(){
        var e = document.getElementById('BotBootInput').value;
        if (e == d) return true;        
        return false;
    }

    $(function() {
        $(".commentblogsubmit").click(function()
          {
          if(ValidBotBoot() == false){
            alert("Error");    
          }else{
            alert("Success !!!");
          }
        return false;
        });
    });

but if i included addthis, the alert allways error
sorry my english is bad


Solution

  • Your code probably conflicts with addthis. Probably a b c or d are used in addthis.

    The easy fix would be to just use variables with different, more descriptive, names. Another thing you could do is have the generation code inside the draw function and have it return the sum. So you say

    var expected = DrawBotBoot();
    

    Then you can pass in that value into the validate function for testing.

    ValidBotBoot(expected)
    

    This way the variables stay within the scope you want them to.