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
精彩评论