简体   繁体   中英

javascript captcha and form not submitting

I have a simple mathematical captcha that seems to work however it now does not allow me to submit my form.

https://jsfiddle.net/qm24Lps8/2/

The js fiddle above contains the full code - bellow is the bottom half of the form. The captcha is amended to the bottom of the message box. There is also the javascript that runs the captcha.

What have I done wrong that stops the form from submitting?

  <div class="mxm-form-item " id="mxm-form-2446-field-3">
                        <div class="mxm-form-field">
                            <textarea rows="2" name="Default.message" id="mxm-form-2446-field-3-el" class="mxm-form-element mxm-form-textarea" onfocus="clearDefaultandCSS(this)">How can we help?</textarea>
                        </div>
                        <div class="mxm-clear"></div>
                    </div>
                    <div class="mxm-form-item " id="mxm-form-38124-field-3">
                        <div class="mxm-form-field">
                            <input type="hidden" name="Default.brochure request" value="no" />
                            <input id="mxm-form-38124-field-3-el" type="checkbox" name="Default.brochure request" value="yes" class="mxm-form-element mxm-form-booleancheckbox" />
                            <label for="mxm-form-38124-field-3-el" class="mxm-form-cb-label">Download our brochure</label>
                        </div>
                        <div class="mxm-clear"></div>
                    </div>
                    <div class="mxm-form-item " id="mxm-form-38124-field-4">
                        <div class="mxm-form-field">
                            <label style="width:120px;" class="mxm-form-item-label"></label>
                            <input type="submit" value="Submit" class="mxm-form-element mxm-form-button" onclick="return(validate());" />
                        </div>
                        <div class="mxm-clear"></div>
                    </div>
                </form>
            </div>
        </div>
        </div>
    </div>

$(function(){

var mathenticate = {
    bounds: {
        lower: 5,
        upper: 50
    },
    first: 0,
    second: 0,
    generate: function()
    {
        this.first = Math.floor(Math.random() * this.bounds.lower) + 1;
        this.second = Math.floor(Math.random() * this.bounds.upper) + 1;
    },
    show: function()
    {
        return this.first + ' + ' + this.second;
    },
    solve: function()
    {
        return this.first + this.second;
    }
};
mathenticate.generate();

var $auth = $('<input type="text" name="auth" />');
$auth
    .attr('placeholder', mathenticate.show())
    .insertAfter('textarea[name="Default.message"]');

$('#mxm-form-38124').on('submit', function(e){
    e.preventDefault();
    if( $auth.val() != mathenticate.solve() )
    {
        alert('wrong answer!');
    }
});

});

Check whether Validate() function defined. It throws error on submit button event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM