Use variable as filter in a query

Hello team
maybe you could help the stupid french newbie that i’am. :smile:

i’ve got a bootstrap Form control that allow me to chose year (annee in french)

Annee
                          <option>2014</option>
                          <option>2015</option>
                          <option>2016</option>
                          
                        </select>

in my js file, i want to use the value of this form as a filter
here is my js code (in a .js file)

function getRecords2() {
var anneeselect2 = $(’#anneeselect’).val());
if (anneeselect2 === ‘’) return;
var anneeselect3 = ““annee=” + anneeselect2 + “””;

alert(anneeselect3);
df.apis.NOUNOUDB.getRecords({"table_name":"heure", "filter":anneeselect3}, function (response) {
    buildItemList(response);
}, crudError
);

}

the Alert show that the variable look correct: "annee=2014"
but the query doesn’t work (no data displayed)

the tricky thing is that if i change my query manualy with
function getRecords2() {
var anneeselect2 = $(’#anneeselect’).val());
if (anneeselect2 === ‘’) return;
var anneeselect3 = ““annee=” + anneeselect2 + “””;

alert(anneeselect3);
df.apis.NOUNOUDB.getRecords({"table_name":"heure", "filter":"annee=2014"}, function (response) {
    buildItemList(response);
}, crudError
);

}

It works…
so my question is, do i miss something,
do i have to do something with value from my form before adding it to my query (i’ve tried parseINT() without success)

thanks for helping,

julien

of course i ve got a button that call getRecords2 function

Try this:

var anneeselect3 = "annee=" + anneeselect2;
1 Like

Thanks toddappleton
i don’t know why i wass sure to have already test this without success
but now it works :smile:

thanks again ,

regards,
julien

1 Like