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

Question

Question

How to use javascript to display submit button if two columns in dynamic row meet criteria

asked on March 30, 2016 Show version history

Hello.  I am hiding the submit button by default.  I would like to show it once the data in the form meets the following requirements.

If, in any given row, the value in the Type column = "Run" then the Good pcs needs to be greater than 0 to show the submit button.  The type column is a dropdown field and the Good pcs is a line field.

 

I am not sure how to do the if statement to say, If Type = Run and Good pcs >0 then display submit button.  (I  know how to display the submit button, just not the right way to code the if statement.

Any suggestions?

 

Thanks

0 0

Answer

SELECTED ANSWER
replied on March 31, 2016 Show version history

Hi Jason,

You can use JavaScript "if" statements to check that the value is greater than zero. Here is some sample code to get you started:

$(document).ready(function(){
  $('.table').on('change click', check);
});
function check(){
  $('.cf-table-block tbody tr').each(function(){
    $('.Submit').hide();
    var type = $(this).find('.type input').val();
    var good = parseNumber($(this).find('.good input').val());
    if (type == 'Run' && good == 0){
      return false;
    }
    $('.Submit').show();
  });
}
function parseNumber(n){
  var f = parseFloat(n);
  return isNaN(f)?0:f;
}

Make sure to give your table the CSS class "table", your "Type" column field the class "type", and your Good PCS column field the class "good".

Let me know if this works for you!

1 0

Replies

replied on April 1, 2016

Thank you for helping.  However, it does not work.  The submit button will display even if a row with Setup type Run and Good pcs 0 exist.

 

0 0
replied on April 1, 2016

Hi Jason,

Works for me! Here's a video: http://screencast.com/t/pjYzRtCV

Make sure that your "Type" field is a drop down (looks like a single-line in your picture).

0 0
replied on April 1, 2016

Oh man, you are right.  surprise That field is a single line.  Im sorry.  

I looked at your video.  Nice.  And Thanks.  

Does it make a difference, that in my scenario, my table is generated dynamically from a SQL lookup in forms?  When the page loads, it has a single row with no data.  Then, the user must select the user and date from another area in the form and then Forms query's a SQL database and populates a table dynamically.

Also, since the Type field is single line and not drop down as you discerned, what change does that require of the script?

 

Thank you very much!

0 0
replied on April 1, 2016

I do not think it will matter if the table is populated. 

I've updated the code to account for the field being a single-line.

Let me know if it works!

0 0
replied on April 1, 2016

Works great!  Thank you very much/

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

Sign in to reply to this post.