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

Question

Question

Lookup rule for field populated by Javascript/jQuery

asked on July 24, 2015

Is there a way to have the lookup rule work correctly on a field populated via JavaScript?

I have an HR database and want a simple form with a single lookup field to find an employee and return their name, desk number, phone extension, etc. The catch is I also want them to be able to search on multiple criteria through one field.

I tried having multiple lookup rules for the same field but after it returned the information it would wipe it out a second later, most likely due to the next lookup failing.

Now I have tried using invisible fields with their own lookup rules. These fields are populated by jQuery script depending on what type of information is entered into the lookup field.

For example here is a simple test for two possible lookups. Seat numbers are 3 digits and phone extensions are 4 digits. Field q22 has a lookup rule for seat numbers and q20 has a lookup rule for extension numbers.

$(document).ready(function() {
  $('#q17 input').change(function() {
    if ($(this).val() < 999) {
      $('#q22 input').val($(this).val());
    }
    else if ($(this).val() > 999) {
       $('#q20 input').val($(this).val());
    }            
  }); 
});

The fields populate but nothing is returned from the database unless I manually change fields.

0 0

Answer

APPROVED ANSWER
replied on July 24, 2015

Please try the suggestion from this thread. After you set the value into q22 or q20, use a change event.

1 0
replied on July 27, 2015

Thanks! That was very informative.

All I needed to do was add the line below after copying the value to trigger a change.

$('#qid input').change();

0 0

Replies

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

Sign in to reply to this post.