Welcome Guest, Not a member yet? Register   Sign In
why after click on tag <a>, page refresh and not work appendTo in jQuery?
#1

[eluser]SaSa[/eluser]
tag a is to $.each(). see my js code:

Code:
$('.auto_complete').keyup(function () {
                var id = '#' + this.id;
                var alt = $(id).attr('alt'); var id = $(this).attr('id'); var name = $(this).attr('name');
                var url = alt + id + '/' + name;
            var dataObj = $(this).closest('form').serialize();
            $.ajax({
                type: "POST",
                url: url,
                data: dataObj,
                cache: false,
                dataType: 'json',
                success: function (data) {
                    $(".list_name").show().html('');            
                    $.each(data.name, function(a,b){
                        $(".list_name").append('<p><a href="" id="result">' + b + '</a></p>');
    ////////////////////here/////////////////////
                        $('.list_name p a').live('click', function(e) {
                                    e.preventDefault();
                                    $('<b>' + b + '، </b>&lt;input type="text" name="hotel[]" value="' + b + '" style="border: none; display: none;" /&gt;').appendTo('.auto_box span');
                                    $(this).remove();
                                return false;
                                });
    /////////////////////////////////////////////
                    });
                    if($('.auto_complete').val()==''){
                        $(".list_name p").hide().remove()
                    }
                    $('body').click(function(){
                            $(".list_name p").hide().remove();
                            $('.auto_complete').val('');
                        });
                },
                "error": function (x, y, z) {
                    // callback to run if an error occurs
                    alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
                }
                });

            });

php:
Code:
function search_hotel(){
            $search_term = $this->input->post('search_hotel');
            $query = $this->db->order_by("id", "desc")->like('name', $search_term)->get('hotel_submits');
            $data = array();
            foreach ($query->result() as $row)
            {
               $data[] = $row->name;
            }
            echo json_encode(array('name' => $data));
    // echo: {"name":["333333","\u0633\u0644","\u0633\u0644\u0627\u0633\u06cc","\u0633\u0644\u0627\u0633\u0633","\u0633\u0644\u0627\u0645"]}
        }

If you pick the .live, after click on '.list_name p a' appendTo is several result?

Quote:like:
all result isConfusedalsh، salasi، salaso، salal
when click on- salshh -> displaying(.appendTo) -> salsh، salasi، salaso، salal
when click on- salasi -> displaying(.appendTo) ->salasi، salaso، salal
when click on- salaso -> displaying(.appendTo) ->salaso، salal
when click on - salal -> displaying(.appendTo) ->salal

I want append to only value that clicked, no several value.
Please help me. Frustrate me...
With respect
#2

[eluser]SaSa[/eluser]
Please help me
#3

[eluser]bgreene[/eluser]
had that problem before. i think solution was to give href a hash like: <a href="#" id="result">
#4

[eluser]bgreene[/eluser]
also, i always use <a href="#">xyz</a>
#5

[eluser]SaSa[/eluser]
please see this link and click on image +, and go to filde "insert hotel" and type any of this word: salsh, salasi, salaso, salal, 333333
http://www.binboy.gigfa.com/auto/
please tell me what is bugs?




Theme © iAndrew 2016 - Forum software by © MyBB