House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  JQuery

one of three formfields required

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
03/22/2011 08:14 PM

I've got a small validation question. What's the best/easiest way to validate a form to make sure that one of three different fields have a value. For example, I have three phone number fields (home,work,cell). I'd like a phone number in at least one of those fields. I can do it on the server side but I'd prefer the client as well. Thanks

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
03/22/2011 09:15 PM

I think this will work: if    (    $('#field1').length == 0         && $('#field2').length == 0         && $('#field3').length == 0   )       { $('#errorMessage').show();    } You've got to have something in at least one of the fields to not get the error message. Poking around a bit, I found the 'empty' method, too: if    (    $('#field1').is(':empty')         && $('#field2').is(':empty')         && $('#field3').is(':empty')  )       { $('#errorMessage').show();    } Even shorter: if    (    !$('#field1').val()         && !$('#field2').val()         && !$('#field3').val()        )       { $('#errorMessage').show();    } Need more explicit code? Rick I've got a small validation question. What's the best/easiest way to validate a form to make sure that one of three different fields have a value. For example, I have three phone number fields (home,work,cell). I'd like a phone number in at least one of those fields. I can do it on the server side but I'd prefer the client as well. Thanks


<< Previous Thread Today's Threads Next Thread >>

Search jquery

May 21, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference