开发者

jquery validate input but use id for identifying fields

I have fields in following format:

<input type="text" name="cities[]" id="city_zip1"/>
<input type="text" name="cities[]" id="city_zip2"/>
<input type="text" name="cities[]" id="city_zip3"/>

Is there a way to make first one required by validate plugin, but to leave name as it is? Or to make one of th开发者_如何学Pythonese three required, but to leave name as it is.


Done on click for example. Can be done on submit.

$("#checkforvalue").click(function(e) {
    e.preventDefault();
    if ($("input#place_of_services:checked").val()) {
       var zipentered = false;
       $("input[id^='city_zip']").each(function() {
           if ($(this).val().length) {
               zipentered = true;
           }
       });

       if (zipentered) {
           alert("value in one of the fields");
       } else {
           alert("no value entered");
       }
   }
});

js fiddle example

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜