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

Question

Question

Populate Single Line Field If Populated Drop-Down Contains Value

asked on April 5, 2017 Show version history

We have a form that has a Table that includes a drop-down field that is populated from a database lookup. There is a hidden single line field outside of the table. The table can have values manually added to it or it can be pre-populated based on another field outside of the table.

I am in need of some JavaScript that will evaluate the selected values of the drop-down field for each row, whether done by the lookup or manually selected, and if any of the values contain ASK add the value of Yes to the single line field outside of the table.

Anyone have any ideas?

1 0

Replies

replied on April 5, 2017

This is what we had come up with so far, but it is not working. 

$(document).ready(function () {
// look for ASK content in the table and if found the write TRUE to the ASK control field

$('.cf-table-block').on('click', '', ASKTrueFalse);


function ASKTrueFalse() {
    var foundstate = "blank";
      $(this).find('input').each(function () {
        if ($(this).closest('td').siblings('td.SoftwareApp').find('select').value.contains("ASK")) { 
          foundstate = "True" 
        } 
        else { 
          foundstate = "False"; 
        }
      });
     $('.ASKControl input').val(foundstate);
	}
//end Look for ASK content
}); 

We have narrowed down that the problem is everything after var foundstate = "blank";

Any ideas what needs to be changed?

1 0
replied on April 5, 2017 Show version history

Haven't done any testing, but off the top of my head, I don't think it knows what $(this) is referring to in line 9.  In line 10 $(this) would be each instance of input fields it is iterating through, but on line 9, I don't think $(this) refers to anything since you are not passing in a value on your function...

Maybe replace lines 4 through 7 with: 

$('.cf-table-block').on('click', function ()  {

Closing bracket:   }   would need to change to statement closure as well:    });

0 0
replied on April 5, 2017 Show version history

This hasn't been tested, but something like this could get you started. You would have to trigger the code on Blur, Change or something.

I'm sure there is a much more elegant way, I just thought of this as a quick solution.  

i = 0;
$('.yourOption_id option').each(function() {
 
  
var yourOption_id = $(this).val();

         if (yourOption_id == 'ASK') {

                 i++;

         }
  
  
          });  
    


if (i > 0) {
      $('.yourOutsideField').val('Yes');
}

 

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

Sign in to reply to this post.