Is there a way to set the number of rows in a collection from another variable in a form? For example, if we have a form that has a variable for number of guests, we need the number of rows for Guest Information to match that variable. Meaning, if the number of guests is set to 2, this should create a collection with 2 rows.
Question
Question
Answer
Hi Jen, try this code, where 'theNumber' in this case is the field you want to base the number on, and substitute #q15 for the collection id you are going to use:
$('.theNumber input').change(function(){ var numberCols = $('.theNumber input').val(); for (var i = 0; i < numberCols; i++){ $('#q15 .cf-collection-append').trigger('click'); } });
Hope this helps,
Rick
Replies
I must be missing something. My collection settings match yours but it's still not working. What type of field are you using for 'theNumber'? I've tried using a Number field as well as a Single line but neither is working.
It's just a Single Line Field....make sure the #q number ID is for the Collection Header instead of for the first field in the collection. It also has to be inside a document ready function.
I got the code sorted out and it's working!! Thank you so much for your help.
I am still pretty new to LaserFiche and Javascript.
I am trying to make sure that my code is correct, since it isn't working...
I am trying to create the collection based off a number (which is a single line field)
$(document).ready(function() { $('.Substandard').change(function(){ var numberCols = $('.Substandard').val(); for (var i = 0; i < numberCols; i++){ $('#q109 .cf-collection-append').trigger('click'); } }); }
Bryant, use $('.Substandard input') and try that, instead of $('.Substandard')