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

Question

Question

Javascript alert for table

asked on November 24, 2016 Show version history

hi everyone.

I am populating the field GPID and GPID copy with Look up rules, that works fine.
I am trying to bring up an alert every time this happens but it does not seem to work.

Any help will be appreciated.

here is my code and a screen shot of my form.

 

$(document).ready(function() { 
  
$('.cf-table-block').change(check)
  function check()
  {
  $('.cf-table-block tbody tr').each(function () {
    var value = $(this).find('.gpid input').val(); 
    var copy = $(this).find('.copy input').val(); 
    
    if (value == copy){
       alert("match");
       $('.Submit').hide()
    }
    else{
       $('.Submit').show()
        }
});
});

 

0 0

Answer

APPROVED ANSWER
replied on November 25, 2016

its matching the empty columns, replace the if statement with if(value === copy && value)

1 0

Replies

replied on November 24, 2016 Show version history

You are missing a curly bracket. You will also want to modify your check function, as currently past matches will yield the alert as you add more rows. You should change it so it only check the current row.

$(document).ready(function() { 
  
$('.cf-table-block').change(check);
  function check()
  {
    $('.cf-table-block tbody tr').each(function () {
      var value = $(this).find('.gpid input').val(); 
      var copy = $(this).find('.copy input').val(); 

      if (value == copy){
         alert("match");
         $('.Submit').hide()
      }
      else{
         $('.Submit').show()
      }
	});
  }
});

 

0 0
replied on November 25, 2016

hi Xavier, the code still does not work, it alerts the user whether or not it matches.

replied on November 25, 2016

hi Xavier, thanks for the help but the code still brings up the alert whether or not it matches.

0 0
APPROVED ANSWER
replied on November 25, 2016

its matching the empty columns, replace the if statement with if(value === copy && value)

1 0
replied on November 27, 2016

thanks Xavier, it worked like a charm :)

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

Sign in to reply to this post.