javascript - jQuery validation of two fields len(). -
guys using jquery validation plugin validate input text fields...
like this:
$("#formsettings").validate({ rules: { sta: { required: true, }, crs: { equalto: "#password" } }, messages: { email: { required: "please provide email address", email: "provide valid email address" }, });
the issue: need match 1 textfield value other, each textfield have comma separated values , should match before continuing, idea how can
like if textfield 1 is: 1,2,3,4,5,6 textfield2 should match.
$('#selector').val().length
above basic jquery version of .length after if statement. here brief untested test try:
<input type="text" value="1,2,3,4,5" id="thing1"> <input type="text" value="1,2,3,4" id="thing2"> <input type="button" name="submit" value="submit" id="submit"> $('#submit').click(function(event){ var thing1 = $('#thing1').val().length; var thing2 = $('#thing2').val().length; if (thing1 == thing2) { return true; } else { alert("contents must have same length"); return false; } });
and fiddle: http://jsfiddle.net/8xqb3/
Comments
Post a Comment