-1

I have to add click event to the dynamic list view. When I click this list it redirect to more detail page. I am fetching the list of Hotels available in particular area and insert into list-view. Now when I click any particular list Hotels redirect to more detail page. check the following image list view of list of hotels available. Every hotel have unique id So when I click any list it will use that unique hotel id and fetch more details information of that hotel from server and show on one dedicated page for that particular Hotel. My Question is How I add click even on dynamic list view and pass that unique Hotel Id so that later I am able to fetch more information from server using that Hotel Id.

enter image description here

My script code, How to add click even in dynamic list

    <script> 
                $(document).ready(function(){ 
                    $("#btnReg").click(function(){ 
                        $("#listHotelsOptions").empty();
                        var distance = document.getElementById('distance_id').value; 
                        var output=""; 
                        var hiddenId="";
                        $.ajax({ 
                                url:"http://192.168.1.4/Experiements/webservices/getHotels.php", 
                                type:"GET", 
                                dataType:"json", 
                                data:{type:"login", Distance:distance}, 
                                ContentType:"application/json", 
                                success: function(response){ 
                                console.log(response) 
                                    $.each(response, function(index,value){     
            output+='<li class="hotelDetails"><a href="#hotelPage" style="text-decoration:none;">
  <img alt="chef" src="./images/chef.min.png" width="20px" height="20px" >'+value.Hotel.Name+'   
  has'+value.Hotel.Rooms+'</a></li>';
                            }); 
                            $(".hotelDetails").live('click',function(){


                            });
            $("#listHotelsOption").append(output).listview().listview('refresh'); 
                            }, 
                                error: function(err){ 
                                alert(JSON.stringify(err)); 
                            } 
                        }) //ajax 
                    }); //click 
                }); //ready 
    </script>
Neelabh Singh
  • 2,600
  • 12
  • 51
  • 88
  • possible duplicate of [How to add click event to dynamic list view in PhoneGap?](http://stackoverflow.com/questions/27833594/how-to-add-click-event-to-dynamic-list-view-in-phonegap) – jcesarmobile Jan 08 '15 at 10:10
  • stop opening new threads with the same question again and again – jcesarmobile Jan 08 '15 at 10:11

2 Answers2

0

you can put class like .listClass in every item of list and add javascript function like

$(".listClass").click(function(){
 called on each item click
})

and its working fine here link

Vijay Patel
  • 163
  • 2
  • 14
  • I am not sure about phonegap but It must work on javascript. Then try to put it in 's class or create function and assign to 's onClick="function()" it will work for sure. – Vijay Patel Jan 08 '15 at 10:27