开发者

jquery validation error replacing select list value

开发者 https://www.devze.com 2023-01-18 10:22 出处:网络
Is it possible to replace a select list (that开发者_StackOverflow is required) default value with an error message if it isn\'t changed? EX if you click submit without selecting a value, replacing the

Is it possible to replace a select list (that开发者_StackOverflow is required) default value with an error message if it isn't changed? EX if you click submit without selecting a value, replacing the default "Please Select" that has no option value with a "Please select an option" message? If so, how?


$.validator.addMethod(
            "SelectTechnology",
            function(value, element) {
                if (value == '0'){
                    $('#singleTech option[value="0"]').text("You forgot to select one!");
                    return false;
                } 
                else 
                    return true;
            },
            "Please Select a Technology"
        );

http://jsfiddle.net/X8rS6/


u can do this like below

$("#selectlist option:first").html("you should select value");

if that option without value is ur first one

0

精彩评论

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

关注公众号