Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
验证表单JAVASCRIPT中启用的字段_Javascript_Jquery_Html - Fatal编程技术网

验证表单JAVASCRIPT中启用的字段

验证表单JAVASCRIPT中启用的字段,javascript,jquery,html,Javascript,Jquery,Html,你好,我正在编写代码,我遇到了一些问题 我为我的表单创建了一个验证,表单有一个下拉菜单,其中有3个选项。如果他们选择其中一个选项,则会启用4个输入字段。我创建了一个函数来验证选择后启用的行。唯一的问题是,当我选择其他两个选项(验证应该禁用)时,它不应该为这些输入字段进行验证,因为我不会将任何数据放在那里。我需要帮助!我想在启用时验证它们,如果输入字段是禁用的,则不应验证 我的密码是这个 字段: Otheremail和other address是在表单的下拉菜单中选择一个选项后启用的字段 func

你好,我正在编写代码,我遇到了一些问题

我为我的表单创建了一个验证,表单有一个下拉菜单,其中有3个选项。如果他们选择其中一个选项,则会启用4个输入字段。我创建了一个函数来验证选择后启用的行。唯一的问题是,当我选择其他两个选项(验证应该禁用)时,它不应该为这些输入字段进行验证,因为我不会将任何数据放在那里。我需要帮助!我想在启用时验证它们,如果输入字段是禁用的,则不应验证

我的密码是这个

字段: Otheremail和other address是在表单的下拉菜单中选择一个选项后启用的字段

function validate() {
    if($('#response :selected').val() == '0') {
        alert('Debe seleccionar al menos un Agente.');
        return false;
    }

    if($("#otheremail").val()=='')
    {
        alert("Por favor complete todos los campos");
        $("#otheremail").focus();
        return false;
    }

    if($("#otheraddress").val()=='')
    {
        alert("Por favor complete todos los campos");
        $("#otheraddress").focus();
        return false;
    }

};

您可以检查是否选择了启用字段的选项,否则跳过验证

function validate() {
    //if the option which enables the fields are not selected do not proceed with validation
    if ($('#myselect').val() != 'somevalue') {
        return true;
    }

    if ($('#response :selected').val() == '0') {
        alert('Debe seleccionar al menos un Agente.');
        return false;
    }

    if ($("#otheremail").val() == '') {
        alert("Por favor complete todos los campos");
        $("#otheremail").focus();
        return false;
    }

    if ($("#otheraddress").val() == '') {
        alert("Por favor complete todos los campos");
        $("#otheraddress").focus();
        return false;
    }

};