javascript - Issue with getting selected value of select menu in query? -


there select menu in page loads values db. able view values in select menu. while displaying selected value, not able display properly. i.e. if value contains spaces not getting full value( ex: if selected "wilson garden", getting "wilson". displaying "wilson garden" in select box, when try value on change event got "wilson",same thing happen values has space in it.

my html code is:

<select name="select-choice-1" id="select-choice-1">  <option value="select category">select category</select> </select> 

and jquery code follows,

     $("#select-choice").on('change', function(event) {               alert( this.value );               console.log("category is: " +this.value); // here getting value..                 }); 

// store values dynamically in select menu..

$(document).on("pagebeforeshow","#homepage",function(){       var db = window.sqliteplugin.opendatabase({name: "mydb"});      db.transaction(function (tx) {        tx.executesql("select distinct category locationlog;", [], function (tx, res) {             (var = 0; < res.rows.length; i++) {                  $("#select-choice").append('<option value='+res.rows.item(i).category+'>'+res.rows.item(i).category+'</option>');               }             $("#select-choice").listview('refresh');           });          });       }); 

it because didn't quote attribute. need wrap values around double quotes.

var opt  = '<option value="';     opt += res.rows.item(i).category;     opt += '">';     opt += res.rows.item(i).category;     opt += '</option>';  $("#select-choice").append(opt); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -