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

Question

Question

Compare two fields show message

asked on June 29, 2023

I have a use case where I would like to compare the values of two fields and display a warning message if they are not identical.  Either by displaying a hidden field or by some other method.

Does anyone have a similar example?

0 0

Answer

SELECTED ANSWER
replied on June 29, 2023

You can do this using JavaScript:

$(document).ready(function(){
$("#q3").hide();
$("#q1 input, #q2 input").change(function(){
	if ($("#q1 input").val() != $("#q2 input").val()) {
      $("#q3").show();
    }
    else {
      $("#q3").hide();
    }
});
});

 

0 0
replied on June 29, 2023

Thanks! This works great!

1 0

Replies

replied on June 29, 2023

Someone else may be able to provide a more elegant solution, but here's how we have handled this in a form where a username is entered, and then re-entered for verification.

We have three hidden fields.

verify_1_notblank uses the field formula: =IF(first_field <> "",1,0)
verify_2_notblank uses the field formula: =IF(second_field <> "",1,0)
accountname_verification uses the field formula: =IF(first_field=second_field,1,0)

We then display an HTML box that says "Username mismatch" using the Field Rules shown in the attached screenshot.

The "not blank" fields prevent the HTML from showing when both fields are blank, before any values are entered into the form.

I hope that helps!

Note: the screenshot shown is from v10 (or Classic Designer), but it should work the same way in the v11 Forms Designer

field_rules.png
field_rules.png (22.21 KB)
0 0
replied on June 29, 2023

I think @████████'s post with hidden fields and field rules to display a warning message will be the simpliest to implement. 

There are lots of examples here on Answers (like this one) about using Javascript to add custom parsley validation to the fields.  These should work in version 10 (based on your tagged topic for the post).

If what you are comparing is email addresses, and this is something you do regularly, it might be worth upgrading because Forms 11 added out-of-the-box comparison of email fields in the new Forms Layout Designer.

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

Sign in to reply to this post.