开发者

dropdown focus on page and enter key press check using jquery/javascript

开发者 https://www.devze.com 2022-12-17 05:21 出处:网络
a dropdown with focus and enter key pressed validate for form. I have a form with elements that are validated by jquery (in the validator function as below)

a dropdown with focus and enter key pressed validate for form.

I have a form with elements that are validated by jquery (in the validator function as below) If I have a textbox, and I enable focus on it and press enter, I get all of Javascript validations.

$( document ).ready(function() {
        var container = $('div.errors');

            $("mydropdownId").focus(); //tried this , focus works, but enter key press check  doesn't work 
            // validate the form when it is submitted
        var validator = $("#coverageForm").validate({
        invalidHandler: function() {
            $('#form_error_notice').css('display', 'block');
            $('.server_error_notice').css('display', 'none');
                $('.errorsServer').css('display', 'none');
                hintAgain();
        },
         submitHandler: function(){

            DoDisable(); //changes couple of divs and does document.form.submit();
            },
      errorContainer: $("#coverageForm .errors"),
                errorLabelContainer: $("ul", "#coverageForm .errors"),
                    wrapper: 'li',
                    meta: "validate"
        });
    // Control input in numeric form fields
    $('input.numeric').numeric();
开发者_如何学Python    // Initiate overlays
    $('.boxy').boxy({modal: true});
});

I am new to jquery, anyone who could guide me towards the light? I don't want to change the validation that jquery provides. It is a stringe requirement from my "client"!

Thanks in advance!


The default behavior for a html form is that when you click enter the form is submitted. So that kicks JQuery.Validator off to validate the fields on the form.

So to get around this, you might have to capture the keydown or keypress events, get the enter key down, then move to the next field manually (call focus on the next control)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号