0

In my application one select menu and list menu are there, I want to fill the values dynamically from DB. I am able to fill values in to select menu dynamically, but How can I fill it in list view, Can Any one tell me how to fill the values dynamically in list view, My is as follows,

for (var i = 0; i < res.rows.length; i++) {
 var opt  = '<option value="';
 opt += res.rows.item(i).Location;
 opt += '">';
 opt += res.rows.item(i).Location;
 opt += '</option>';
 $("#select-choice-location").append(opt);
  }

HTML:

<select name="select-choice-location" id="select-choice-location">
                  <option value="Select Location">Select Location</option>
   </select>
  <ul data-role="listview" id="locationList" name="locationList" data-inset="true">
       <li><a href="#">Select Location</a></li>
   </ul>

Select menu is working fine how to write same syntax for list view to get dynamic values.

2 Answers 2

2

jQuery has a clean method for creating elements with attributes jQuery(html, attributes) (Link)

Try using it to create your HTML and then append it to the necessary container:

for (var i = 0; i < res.rows.length; i++) {
    // create and append the option tag
    $('<option/>', { value: res.rows.item(i).Location, text: res.rows.item(i).Location})
        .appendTo("#select-choice-location");

    // create and append the li tag
    $('<li/>', { text: res.rows.item(i).Location})
        .appendTo("#locationList");
}

Similar Example

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

for (var i = 0; i < res.rows.length; i++) {
 var opt  = '<li value="';
 opt += res.rows.item(i).Location;
 opt += '">';
 opt += res.rows.item(i).Location;
 opt += '</li>';
 $("#locationList").append(opt);
  }

Assigning click event

$(document).on('click','#locationList li',function(){

});

3 Comments

Yes it is working fine. Now How can I do on click event on <li> value
click event or <a> tag element
@user3300593 i added jquery click method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.