Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Dynamic Select List Item

Hi,

I asked a question about adding items to a select list https://getsatisfaction.com/apperyio/...
I have followed the tutorial and I am successfully adding items to the list,

var text = results.rows.item(i).Registration;
dropDown.append('​' + text + '');

When an Item is selected from the list I am writing the selected item to a local storage variable:

var str = "";
$("select option:selected").each(function () {
str += $(this).val() + ' ' ;
});
str = str.replace(' on', '');
if (str.substring(str.length-1) == " ")
{
str = str.substring(0, str.length-1);
}
localStorage.setItem('_reg', str);

then using the variable to query a phonegap sql table the query returns no row although the matching record exists in the table .

It appears that the query fails because the string held in the select list item has characters or spaces added. I am able to query the table successfully by hard coding the query parameter to the value shown in the select list which is what leads me to believe that the value returned from the select is not the same as the displayed value. I hope you are able to follow all of this and advise me on how to return the true value from the select.

Regards,
Joe

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Dynamic Select List Item

Hello Joe!

  1. Please check if the string you receive has unnecessary symbols. Look at the localStorage variable value ( check developer's tools or use console.log(localStorage.getItem('_reg'))
  2. To delete extra newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the string use the function trim() http://api.jquery.com/jQuery.trim/
Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Dynamic Select List Item

Hi Alena, Thanks for your reply I was using trim but not in the correct location! I have updated my code and I am now got the result I was expecting,

Return to “Issues”