Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Unable to query database when value in Select Menu changes.

First let me say thanks to Appery for the platform as a new developer I am happy that I was able to put something really decent over a weekend!! But have a question though:

I have 3 values in my select menu ( License #, Sacco, Route#) and one input box below it. What I want to do is allow the user to query the database and if they choose License #, they search DB for those values if they switch to Sacco they search sacco etc.

The original code that assume user is only searching for License # is working:

//Search for all license
return '{"License_Number":"'+value+'"}';

But I am struggling implementing the select menu functionality, I have played with number of option and nope e.g.

var newData = $($(Appery("Review_selectmenu")).find("option:selected")).attr("value");
//Loop through the DB and glab all values
return '{"newData":"'+value+'"}';

Review_selectmenu= Name of my select menu.
SearchReview_textinput= My text box where users enter values.

Image Image

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Unable to query database when value in Select Menu changes.

I forgot to include one thing..The text the user inputs in the text box will need to be converted to all caps and any spaces between text removed. I think have an idea how this should be done but where to put it I think am failing:

//Convert Text to ALL CAPS
var SearchText= Appery('SearchReview_textinput').value();
SearchText.toUpperCase();

What function should I use to remove spaces e.g. good boy= goodboy
I tried trim: trim(SearchText); but it failed, tried many others also and I was putting my code here:
Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Unable to query database when value in Select Menu changes.

Hello Joe,

1) We can see only one link in the mapping, but you have 2 returns, could you please show us the js code for where parameter?
2) Please try this
preAppery("Review_selectmenu").selectmenu()[0].selectedOptions/pre

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Unable to query database when value in Select Menu changes.

Evgene, Yes there is only one link which goes to "where" and this is what I had but did not work:

//Loop through the DB and glab all values

var newData = $($(Appery("Review_selectmenu")).find("option:selected")).attr("value");

return '{"newData":"'+value+'"}';

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Unable to query database when value in Select Menu changes.

Hi Joe,

Please simplify your JS in the where clause with following:

pre

var selectValue = Appery("Review_selectmenu").val();

console.log("currentSelect value = " + selectValue);

var whereObject = {"newData": selectValue};

return JSON.stringify(whereObject);

/pre

Also, by your code you try to filter by "newData" collumn, is it correct?

Regards

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Unable to query database when value in Select Menu changes.

Thanks Yurii, I have tried the code but it doesn't give me any results. For example in the screen shot below which assumes the user will always be searching for license #, I can populate the grid with all the values that match the search criteria entered in the textbox I acomplish this by using this code:

codereturn '{"License_Number":"'+value+'"}'; /code

SearchReview_textinput= Text box where user enters data

I have tried to make subsitutions in your code; for example,
codevar whereObject = {"newData": selectValue}; with var whereObject = {"SearchReview_textinput": selectValue};
/code

but still doesn't work Image Image

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Unable to query database when value in Select Menu changes.

I got it working here is the code I ended up using:

code
//Get the selected value from the drop down and Loop through the DB and glab all values

var selectValue = Appery("Review_selectmenu").val();

if (selectValue == 'License Number')
{
return '{"License_Number":"'+value+'"}';
} else if (selectValue == 'Sacco') {
return '{"Sacco":"'+value+'"}';

} else {
alert("Unknown Error- Try Again!");
}
/code

Return to “Issues”