You are viewing limited content. For full access, please sign in.

Question

Question

test two fields to make sure only one if filled

asked on January 29, 2018 Show version history

I am wanting to look at two fields and verify that only one field has a value.  the code below is what I am using but it does not appear to work correctly.  

any ideas or suggestions would be greatly appreciated.  

 

//compare values for .miles and .gas
$(document).ready(function() {
  $('.Submit').hide();
  $('.miles input').on('blur change', function() {
    if($('.miles input').val() > $('.gas select').val()) || ($('.gas input').val() > $('.miles select').val(){
      $('.Submit').show();
    } else {
      $('.Submit').hide();
    }
  });
});

mileage == miles

Transportation == gas

0 0

Replies

replied on January 29, 2018

Hi Ramika,

 

You can use Field rule for that.

(sorry for the printscreen, this is a french version)

 

You can hide or show fields depending from anothers fields

0 0
replied on January 29, 2018

It's not only about the show/hide I need to be sure only one field has a number greater than zero in it.  Thank you for the suggestion.  

0 0
replied on January 29, 2018

You can use Field Rule for that too.

 

If (valueA < 0 or = 0 ) => show error message

if (valueA > 0) => hide error message

 

You can mixte conditions.

 

Next, if error is visible hide submit's button.

0 0
replied on January 29, 2018

okay, I can use a field rule to show or hide fields.  That would work if this is all i'm trying to accomplish.  However, I want to make sure that if fieldA is 30 that fieldB is 0 AND if fieldB is 45 the fieldA is 0.  Also, I would prefer to use javascript because I have rules acting on those fields already.  

0 0
replied on January 29, 2018

I understood.

What I means is

You can show error if (A > 0 AND B > 0) or (A = 0 AND B = 0)

and you can hide error if (A > 0 AND B = 0) or (A = 0 AND B > 0)

Then if (error is visible) using javascript => hide submit

or if (error is invisible) using javascript => show submit

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.