# Use variable as filter in a query

**URL:** <https://community.dreamfactory.com/t/use-variable-as-filter-in-a-query/1098>\
**Category:** REST API\
**Created:** [May 13, 2015, 4:07pm UTC](https://community.dreamfactory.com/t/use-variable-as-filter-in-a-query/1098 "2015-05-13T16:07:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [May 13, 2015, 4:07pm UTC](https://community.dreamfactory.com/t/use-variable-as-filter-in-a-query/1098/1 "2015-05-13T16:07:00Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [May 13, 2015, 4:23pm UTC](https://community.dreamfactory.com/t/use-variable-as-filter-in-a-query/1098/2 "2015-05-13T16:23:06Z")

</div>

of course i ve got a button that call getRecords2 function

---

<div class="post-metadata">

**Author:** ![toddappleton](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/toddappleton/32/159_2.png) [@toddappleton](https://community.dreamfactory.com/u/toddappleton)\
**Post date:** [May 13, 2015, 4:24pm UTC](https://community.dreamfactory.com/t/use-variable-as-filter-in-a-query/1098/3 "2015-05-13T16:24:55Z")

</div>

Try this:

```
var anneeselect3 = "annee=" + anneeselect2;
```

---

<div class="post-metadata">

**Author:** ![jeebee](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jeebee](https://community.dreamfactory.com/u/jeebee)\
**Post date:** [May 13, 2015, 4:28pm UTC](https://community.dreamfactory.com/t/use-variable-as-filter-in-a-query/1098/4 "2015-05-13T16:28:02Z")

</div>

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

thanks again ,

regards,  
julien
