Dynamically add form field rows - cakePHP - php

I have a invoice table and an invoice_item table. Each Invoice hasMany invoiceItem.
When creating an invoice the user is presented with a form with the invoice form fields and also a row with invoiceItem form fields.
What I want to do is to have a "add new item" link that dynamically (jQuery, AJAX) adds a new row of the item fields. User should be able to add as many rows as they want and each new row should appear below the last row.
Of course the row field attributes must also be correct so that the data can easily be inserted with the saveAll method.
What is the best and most proper way to accomplish this with CakePHP? I am using CakePHP 2.4.7.

Here's how I did it with data containing a hidden id, a label and an input field, all wrapped up in a fieldset. You could use actual tables to wrap it up.
Here's the generated HTML for two sets of fields and the link to click to add a row:
<fieldset>
<input type="hidden" name="data[VmfrDesignatedIncome][0][id]" value="668" id="VmfrDesignatedIncome0Id"/>
<div class="input text">
<label for="VmfrDesignatedIncome0Designation">Designation</label>
<input name="data[VmfrDesignatedIncome][0][designation]" value="blah" maxlength="512" type="text" id="VmfrDesignatedIncome0Designation"/></div>
</fieldset>
<fieldset>
<input type="hidden" name="data[VmfrDesignatedIncome][1][id]" value="669" id="VmfrDesignatedIncome1Id"/>
<div class="input text">
<label for="VmfrDesignatedIncome1Designation">Designation</label>
<input name="data[VmfrDesignatedIncome][1][designation]" value="blah2" maxlength="512" type="text" id="VmfrDesignatedIncome1Designation"/></div>
</fieldset>
Add row
and here's the Javascript which clones the last fieldset on the page, and then modifies the id, name and field values to increase the number in them by one. Note that the selectors have to accurately select each label or field using the > child selector.
/* As the strings to the function below may have [ or ]
** we want to stop it being treated as a regexp
*/
RegExp.quote = function(str) {
return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
};
function findNumberAddOne(attributeString) {
/*Finds the number in the given string
** and returns a string with that number increased by one
*/
var re = new RegExp("(.*)([0-9])(.*)");
var nPlusOne = attributeString.replace(re, "$2")+"+1";
var newstr = attributeString.replace(re, "$1")+eval(nPlusOne)+attributeString.replace(re, "$3");
return newstr;
}
$(document).ready(function() {
/* Duplicate the last set of designated income fields and increase the relevants id/name etc.
** so that it works as a new row in the table when saved*/
$('#addrow').click(function() {
$('fieldset:last').clone().insertAfter('fieldset:last');
$('fieldset:last > input').attr('id',findNumberAddOne($('fieldset:last > input').attr('id')));
$('fieldset:last > input').attr('value',''); /*Blank out the actual value*/
$('fieldset:last > input').attr('name',findNumberAddOne($('fieldset:last > input').attr('name')));
$('fieldset:last > div > label').attr('for',findNumberAddOne($('fieldset:last > div > label').attr('for')));
$('fieldset:last > div > input').attr('id',findNumberAddOne($('fieldset:last > div > input').attr('id')));
$('fieldset:last > div > input').attr('value',''); /*Blank out the actual value*/
$('fieldset:last > div > input').attr('name',findNumberAddOne($('fieldset:last > div > input').attr('name')));
});
});

Please check Dynamic form input fields in CakePHP tutorial. I used same for CakePHP 2.x and also for CakePHP 3.x. One problem in this tutorial is dynamic field ID creation. Each time it create same ID for same dynamic fields, like create GradeSubject for both Grade.0.subject and Grade.1.subject fields. If you need dynamic ID for each fields, you can modify this tutorial as like below.
According to tutorial just change View/Elements/grades.ctp content as:
<?php
$key = isset($key) ? $key : '{{ key }}';
// I changed <%= key %> to {{ key }}
?>
<tr>
<td>
<?php echo $this->Form->hidden("Grade.{$key}.id") ?>
<?php echo $this->Form->text("Grade.{$key}.subject",array("id"=>"Grade{$key}Subject")); ?>
</td>
<td>
<?php echo $this->Form->select("Grade.{$key}.grade", array(
'A+',
'A',
'B+',
'B',
'C+',
'C',
'D',
'E',
'F'
), array(
'empty' => '-- Select grade --',
"id"=>"Grade{$key}Grade"
)); ?>
</td>
<td class="actions">
Remove grade
</td>
</tr>
And also change your add.ctp javascript code as:
<script>
$(document).ready(function() {
//I changed undescore default template settings
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g
}
var
gradeTable = $('#grade-table'),
gradeBody = gradeTable.find('tbody'),
gradeTemplate = _.template($('#grade-template').remove().text()),
numberRows = gradeTable.find('tbody > tr').length;
gradeTable
.on('click', 'a.add', function(e) {
e.preventDefault();
$(gradeTemplate({key: numberRows++}))
.hide()
.appendTo(gradeBody)
.fadeIn('fast');
})
.on('click', 'a.remove', function(e) {
e.preventDefault();
$(this)
.closest('tr')
.fadeOut('fast', function() {
$(this).remove();
});
});
if (numberRows === 0) {
gradeTable.find('a.add').click();
}
});
</script>

the simplest idea got in my mind
1- make your items input with name array (<input type="text" name="items[]"/>)
2- create a button with class "addmore"
3- use jquery clone to duplicate the input on the click event on that button
I think this will help

Related

table data not appering on page load using tablesorter

For load table data using ajax in table sorter i follow https://mottie.github.io/tablesorter/docs/example-pager-ajax.html
Load table data using ajax & mysql in tablesorter plugin
I would prefer to load first 25 record in table when page load . Does the tablesorter pager plugin support this? If so, what am I missing, because the documentation shows this example:i will try to load table data using table sorter.how i will set url
for page load event when i click on next button table record get
successfully.here i need to more setting for load table data when page
load.how i will set total rows ,how to set ajax url it`s not working properly
<?php echo $header; ?>
<script id="js">
$( document ).ready(function() {
// Initialize tablesorter
// ***********************
$("table")
.tablesorter({
theme: 'blue',
widthFixed: false,
sortLocaleCompare: true, // needed for accented characters in the data
sortList: [ [0,1] ],
widgets: ['zebra', 'resizable','filter']
})
// initialize the pager plugin
// ****************************
.tablesorterPager({
// **********************************
// Description of ALL pager options
// **********************************
// target the pager markup - see the HTML block below
container: $(".pager"),
ajaxUrl : '<?php echo SITE_URL."admin/index.php?route=technology/products/get_pro/"?>{page}?{filterList:filter}&{sortList:column}',
// use this option to manipulate and/or add additional parameters to the ajax url
customAjaxUrl: function(table, url) {
// manipulate the url string as you desire
// url += '&currPage=' + window.location.pathname;
// trigger a custom event; if you want
$(table).trigger('changingUrl', url);
// send the server the current page
return url;
},
ajaxError: null,
// add more ajax settings here
// see http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings
ajaxObject: {
type: 'GET', // default setting
dataType: 'json'
},
ajaxProcessing: function(data){
alert();
if (data && data.hasOwnProperty('rows')) {
var indx, r, row, c, d = data.rows,
// total number of rows (required)
total = data.total_rows,
// array of header names (optional)
headers = data.headers,
// cross-reference to match JSON key within data (no spaces)
headerXref = headers.join(',').replace(/\s+/g,'').split(','),
// all rows: array of arrays; each internal array has the table cell data for that row
rows = [],
// len should match pager set size (c.size)
len = d.length;
// this will depend on how the json is set up - see City0.json
// rows
for ( r=0; r < len; r++ ) {
row = []; // new row array
// cells
for ( c in d[r] ) {
if (typeof(c) === "string") {
// match the key with the header to get the proper column index
indx = $.inArray( c, headerXref );
// add each table cell data to row array
if (indx >= 0) {
row[indx] = d[r][c];
}
}
}
rows.push(row); // add new row array to rows array
}
// in version 2.10, you can optionally return $(rows) a set of table rows within a jQuery object
return [ total, rows, headers ];
}
},
// Set this option to false if your table data is preloaded into the table, but you are still using ajax
processAjaxOnInit: true,
// output string - default is '{page}/{totalPages}';
// possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows}
// also {page:input} & {startRow:input} will add a modifiable input in place of the value
output: '{startRow} to {endRow} ({totalRows})',
// call
initialRows: {
total: 100,
filtered: 1
},
// apply disabled classname (cssDisabled option) to the pager arrows when the rows
// are at either extreme is visible; default is true
updateArrows: true,
// starting page of the pager (zero based index)
page: 0,
// Number of visible rows - default is 10
size: 25,
// Saves the current pager page size and number (requires storage widget)
savePages: true,
// Saves tablesorter paging to custom key if defined.
// Key parameter name used by the $.tablesorter.storage function.
// Useful if you have multiple tables defined
storageKey: 'tablesorter-pager',
// Reset pager to this page after filtering; set to desired page number (zero-based index),
// or false to not change page at filter start
pageReset: 0,
// if true, the table will remain the same height no matter how many records are displayed.
// The space is made up by an empty table row set to a height to compensate; default is false
fixedHeight: false,
// remove rows from the table to speed up the sort of large tables.
// setting this to false, only hides the non-visible rows; needed if you plan to
// add/remove rows with the pager enabled.
removeRows: false,
// If true, child rows will be counted towards the pager set size
countChildRows: false,
// css class names of pager arrows
cssNext : '.next', // next page arrow
cssPrev : '.prev', // previous page arrow
cssFirst : '.first', // go to first page arrow
cssLast : '.last', // go to last page arrow
cssGoto : '.gotoPage', // page select dropdown - select dropdown that set the "page" option
cssPageDisplay : '.pagedisplay', // location of where the "output" is displayed
cssPageSize : '.pagesize', // page size selector - select dropdown that sets the "size" option
// class added to arrows when at the extremes; see the "updateArrows" option
// (i.e. prev/first arrows are "disabled" when on the first page)
cssDisabled : 'disabled', // Note there is no period "." in front of this class name
cssErrorRow : 'tablesorter-errorRow' // error information row
});
});
</script>
<section class="page-content">
<breadcrumbs-panel page-title="" class="breadcrumbs" id="menu"></breadcrumbs-panel>
<div class="module">
<div class="width100 gold-border-bottom">
<div class="floatleft">
<h1>View Products</h1>
</div>
</div>
<div class="margin-top10">
<table id="campanion-product" class="tablesorter display responsive">
<thead>
<tr>
<th>Product Name</th>
<th>Part Number</th>
<th>Product ID</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr >
<td data-value=">25"> 1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<style>
.pager input.ts-startRow {
min-width: 30px;
}
</style>
<!--Pagination!-->
<div class="pager width100">
<img src="<?php echo HTTPS_PUBLIC; ?>images/tablesorter-first.png" class="first" alt="First" />
<img src="<?php echo HTTPS_PUBLIC; ?>images/tablesorter-prev.png" class="prev" alt="Prev" />
<!-- the "pagedisplay" can be any element, including an input -->
<span class="pagedisplay" data-pager-output-filtered="{startRow:input} – {endRow} / {filteredRows} of {totalRows} total rows"></span>
<img src="<?php echo HTTPS_PUBLIC; ?>images/tablesorter-next.png" class="next" alt="Next" />
<img src="<?php echo HTTPS_PUBLIC; ?>images/tablesorter-last.png" class="last" alt="Last" />
<select class="pagesize" title="Select page size">
<option value="25" selected="selected">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option id="allRowsTablePaginationOption" value="all">All Rows</option>
</select>
<!--<select class="gotoPage" title="Select page number"></select>-->
</div>
</div>
</div>
</section>
<?php echo $footer; ?>
I may be wrong, but from looking at the URL in the screenshot, there is a second ? which could be causing some trouble if not parsed correctly:
index.php?route=technology/products/get_pro/0?filter&column[0]=1
↑ ↑
The next page button may not be active (not seen in the screenshots) since the server is returning a total_rows value of 25, which equals the size setting. The pager code is assuming that all rows are showing; set this to the total number of entries in the database.
its because of widget i will set those are not working currently I need to kept only zebra widget which is the default & i also set wrong url prams i solved url issue using this url : stackoverflow.com/a/15303766/8064611
One More demo http://jsfiddle.net/Mottie/uwZc2/44/
$("table")
.tablesorter({
theme: 'blue',
widthFixed: false,
sortLocaleCompare: true, // needed for accented characters in the data
sortList: [ [0,1] ],
widgets: ['zebra']
})

Cakephp best way to create secret input

Okay so i have a combobox with two options.
Now if one of the options is selected a new input field should appear.
echo $this->Form->input('group_id', array( 'id' => 'groupId'));
echo $this->Form->input('clientid',array( 'type' => 'hidden', 'id' => 'id_client',));
And for that i would use Jquery to check the values
<script>
$(document).ready(function () {
$("#groupId").change(function () {
if($(this).val() == 2){
// do set visible
}
})
});
</script>
My question is: how can i change the type of the field to visible? i have tried: $('#groupId').show(); also $('#clientid').get(0).type = 'text';
But didnt seem to work and i am starting to wonder if this is the best way of doing such a thing?
$(this).attr('type', 'text');
You're doing it wrong.
type="hidden" is not appropriate to hide UI elements (form fields or anything else).
You should instead use the CSS attribute display. Change your clientid input type to "text". When groupId is not 2, set display: none on your clientid input. When it's 2, set display: block.
With jQuery, you can use $('#clientid').show() and .hide().
For instance:
<select id="groupId"><!-- options... --></select>
<input type="text" id="clientId" />
<script>
$(document).ready(function () {
function showHideClient() {
var show_client = $(this).val() == 2;
$("#clientId").toggle(show_client); // hide or show
}
// we bind the "change" event to the hide/show checking
$("#groupId").change(showHideClient);
// and we call it at page load to hide the input right away if needed
showHideClient();
});
</script>

Jquery Raty start plugin : set score for multiple div

I am using jquery star rating plugin "Raty" https://github.com/wbotelhos/raty.
i am generating a result set from database with PHP. that includes score also. I want set score property for every individual rating component. how can I do that?
I am using this syntax for showing the stars.
$('.stars_small').raty({
readOnly : true,
half : true,
score : 2,
space : false
});
<div class="stars_small"></div>
there are many div in a single page with the class "stars_small" generated dynamically. I want to set "score" for every div.
$('.stars_small').raty({
readOnly : true,
half : true,
score: function() {
return $(this).attr('data-rating');
}
space : false
});
this worked fine for me.
the plugin is adding a hidden textbox in every div with class="stars_small"
like this
<div class="stars_small">
<input type="hidden" name="score" value="3.5" readonly="readonly">
</div>
So I just set the value attribute with number coming from database query.
Try this
$('.stars_small').each(function() {
$(this).raty({
readOnly : true,
half : true,
score : 2,
space : false
});
});
Assuming that you have generated with PHP the JS lines:
// lines of JS generated with a loop in PHP (for the rate content)
var rates = [];
rates.push({...one rate coming from PHP...});
rates.push({...one rate coming from PHP...});
// etc...
You can run you rating star with :
$(document).ready(function() {
$(".starts_small").each(function(index, element) {
$(this).raty(rates[index]);
});
});
Here is what i did:
I created a separate class for each of those star divs:
<div class="star s0"></div>
<div class="star s1"></div>
<div class="star s2"></div>
I also generate the array of values in my template (that is, pass the values from my server-side script to the web page). Like so:
var array = new Array(2.4, 2.9, 5.0);
And then I declare the thing common for all the three "star banners" in the $(".star") call, and set the values in a cycle:
$('.star').raty({
half : true
});
for (i = 0; i < array.length; i++) {
$('.s' + i).raty({
score:array[i]
});
}
For V.2.7 Jquery raty is the form:
If you need to start you score depending of a dynamic value, you can to use callback for it.
You can pass any value for it, not necessarily a data- value. You can use a field value for example.
<div data-score="1"></div>
$('div').raty({
score: function() {
return $(this).attr('data-score');
}
});

How do I dynamically add form elements using PEAR's HTML_Quickform package

How do I dynamically add form elements using HTML_Quickform. I know how this is done using plain HTML form elements and using Javascript (see code below). I wanted to know if this is easy to do using HTML_Quickform. I am still looking at this site: http://devzone.zend.com/article/2699-Generating-and-Validating-Web-Forms-With-PEAR-HTML_QuickForm. HTML_Quickform lets you easily add validation rules. I began creating a similar HTML_Quickform code - but I could not figure out how to dynamically add form elements using HTML_Quickform:
// Our Default Form Options
$opts = array('size' => 20, 'maxlength' => 255, 'id' => 'name1', 'class' => 'clonedInput' );
$form->addElement('text', 'first_name', 'First Name', $opts);
$form->addElement('button','btnAdd', 'Add another name', array('id' => 'btnAdd'));
$form->addElement('button','btnDel', 'Remove Name', array('id' => 'btnDel') );
// Submit button
$form->addElement('image', 'register', 'images/continue.gif');
// Define filters and validation rules
$form->applyFilter('first_name', 'trim');
$form->addRule('first_name', 'Please enter your First Name', 'required', null, 'client');
$formsource = $form->toHtml();
echo $formsource;
?>
The code for the plain HTML with Javascript is as follows:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#btnAdd').click(function() {
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
var newNum = new Number(num + 1); // the numeric ID of the new input field being added
// create the new element via clone(), and manipulate it's ID using newNum value
var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
// manipulate the name/id values of the input inside the new element
newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
// insert the new element after the last "duplicatable" input field
$('#input' + num).after(newElem);
// enable the "remove" button
$('#btnDel').attr('disabled','');
// business rule: you can only add 5 names
if (newNum == 5)
$('#btnAdd').attr('disabled','disabled');
});
$('#btnDel').click(function() {
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
$('#input' + num).remove(); // remove the last element
// enable the "add" button
$('#btnAdd').attr('disabled','');
// if only one element remains, disable the "remove" button
if (num-1 == 1)
$('#btnDel').attr('disabled','disabled');
});
$('#btnDel').attr('disabled','disabled');
});
</script>
<form id="myForm">
<div id="input1" style="margin-bottom:4px;" class="clonedInput">
Name: <input type="text" name="name1" id="name1" />
</div>
<div>
<input type="button" id="btnAdd" value="add another name" />
<input type="button" id="btnDel" value="remove name" />
</div>
</form>
Unless I'm misunderstanding your question, you can't. You're using HTML_Quickform to generate HTML on the server. Once you output $formsource, your php code (and thus HTML_Quickform) cease to execute, so you wouldn't be able to programmatically add anything with HTML_Quickform. So, once you output the HTML to the browser, you can only manipulate your HTML-based form with JavaScript.
One workaround would be to create some HTML form fragments with HTML_Quickform and inject those into your HTML form with AJAX.

dynamic element id with php and jquery

Ok this might be a bit confusing, but here goes. Let's say I have a a few select dropdowns on a page.
<select id="filter" name="filter[]">
<option value="">-- Select Filter --</option>
</select>
<select id="load_choice" name="load_choice[]">
<option value="">-- Select Load_choice --</option>
</select>
<select id="plastic" name="plastic[]">
<option value="">-- Select Plastic --</option>
</select>
These are dynamically filled from a database with an ajax request. Each set of select options are dependent on the previous selection. This is just a snippet of all the select dropdowns, but essentially their selections creates a "product". Here is the javascript that connects to the php (which connects to the DB).
$(document).ready(function() {
$('#filter').change(function(){
$('#load_choice').fadeOut();
$('#loader').show();
$.post("ajax/ajax_load_choice.php", {
country: $('#country').val(),
filter: $('#filter').val()
}, function(response){
setTimeout("finishAjax('load_choice', '"+escape(response)+"')", 400);
});
return false;
});
$('#load_choice').change(function(){
$('#plastic').fadeOut();
$('#loader').show();
$.post("ajax/ajax_plastic.php", {
country: $('#country').val(),
filter: $('#filter').val(),
load_choice: $('#load_choice').val()
}, function(response){
setTimeout("finishAjax('plastic', '"+escape(response)+"')", 400);
});
return false;
});
$('#plastic').change(function(){
$('#UG_tipping').fadeOut();
$('#loader').show();
$.post("ajax/ajax_UG.php", {
country: $('#country').val(),
filter: $('#filter').val(),
load_choice: $('#load_choice').val(),
plastic: $('#plastic').val()
}, function(response){
setTimeout("finishAjax('UG_tipping', '"+escape(response)+"')", 400);
});
return false;
});
});
function finishAjax(id, response){
$('#loader').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
}
NOW, let's say I want to add another of the exact same form with the exact same select options in order to "create another product" on the same page (hence the array on the NAME tag for each select). Since the form is dependent on unique IDs, how could I make the IDs in this chunk of code dynamic?
$('#filter').change(function(){
$('#load_choice').fadeOut();
$('#loader').show();
$.post("ajax/ajax_load_choice.php", {
country: $('#country').val(),
filter: $('#filter').val()
}, function(response){
setTimeout("finishAjax('load_choice', '"+escape(response)+"')", 400);
});
return false;
});
I will eventually have 5 sets of those select groups so the user can create 5 products. How would I make it so I don't have to do id="filter1" and id="filter2" to coincide with $('#filter').change(function....blah blah blah. Basically, can I make ID's in a jquery function dynamic?
It is recommended to have unique ids always.
The main reason is that performing a selector like $('#myId') may give unpredictable results when there are multiple elements in the page with that id.
jQuery relies on the native browser implementation of document.getElementById(), which in most cases returns just the first element found.
If you want to make sure by using jQuery that you have unique id's you can do something like:
$('select[id=filter]').each(function(i,el){
el.id=el.id+'-'+i;
});
If you already have unique id's you can use a prefix selector(^= or |=) like this:
$('select[id^=filter]');
//or
$('select[id|=filter]');
You can see a live example of both in this jsFiddle
Alternately, if you don't care about duplicate ids you can select all elements with a given id (including duplicates) like this:
$('[id=my-id]');
I'm not, really, sure what you're asking. My best guess is something along the lines of:
Using jQuery, can I increment the id fields of the form elements in order that I can add multiple forms to the page, and have each form uniquely identified?
If this is a reasonable understanding of your question, and looking at #Baylor Rae's answer (which is definitely a valid interpretation) I'm not necessarily right, then the following should work:
jQuery
$(document).ready(
function(){
$('#formAdd').click(
function(){
var count = $('#formsBox form').length;
$('#formsBox form').eq(0).clone().appendTo('#formsBox').find('label, input').each(
function(){
if (this.id) {
var curId = this.id;
$(this).attr('id',curId + count);
}
else if ($(this).attr('for')) {
var curFor = $(this).attr('for');
$(this).attr('for', curFor + count);
}
}
);
}
);
}
);
html
<div id="formsBox">
<form action="" method="post">
<fieldset>
<ul>
<li>
<label for="firstInput">First Input:</label>
<input type="text" name="firstInput" id="firstInput" />
</li>
<li>
<label for="secondInput">SecondInput:</label>
<input type="text" name="secondInput" id="secondInput" />
</li>
</ul>
</fieldset>
</form>
</div>
<div id="formAdd">Add another form</div>
Effectively, on clicking the #formAdd div the jQuery finds the form, works out how many there are and stores that as the variable count.
It then clones the first form (without the .eq(0) the first click clones one form, the second click clones two forms and it's exponential thereafter), appends it to the same container (#formsBox, for want of a better name) and then looks for the labels and inputs; if these have an id (input) or a for (label) attribute, it adds the previously-stored count variable to these attributes, uniquely identifying them.
This is a pretty poor explanation, and I'm sure there's a far prettier way of achieving the same end-result in the jQuery, but it does seem to work. There's a JS Fiddle demo here
This is what I came up with, wrap each set of select boxes in a div or something. And then remove their id attribute.
With jQuery you can bind a change and still grab the other two selects like this.
$('select[name=filter[]]').change(function() {
var $parent = $(this).parent();
// hide and show other selects
$parent.find('select[name=load_choice[]]').fadeOut();
$parent.find('select[name=plastic[]]').show();
// make the ajax call
});
// repeat the above code for the others

Categories