javascript - can't access to value tag for show data in jquery , mysql , php -


the below code jquery code:

   $(document).ready(function(){     $("#srchtxt").keyup(function(){         var addresshome = $("#srchtxt").val();         $.post("adrespath",{address:addresshome},function(res){          var json = json.parse(res);             var lenths = json.length;             for(var = 0;i <= lenths;i++)                 {              var city = json[0];             var state = json[1];                     var optionli = "<li id='item'><a href='#' value='"+res+"'>"+city+"-"+state+"</a></li>";             $(".resultsearch .ul").append(optionli);             }         });     });     $(".ul li#item a").each(function(){         $(this).click(function(e){             e.preventdefault();             var index_address,address;             index_address = $(this).parent().index();             alert(index_address);             address = $(this).eq(index_address).attr("value");             $("#srchtxt").attr("value",address);         });     });     $("#srchbtn").click(function(){         alert($("#srchtxt").val());     }); }); 

and below code html code:

    <input type="search" name="srchtxt" id="srchtxt"/> <div class="resultsearch">         <ul class="ul">           </ul>         </div>     <a href="#" id="srchbtn"></a> 

and below code php code:

<?php     $address = $_post['address'];     $querysrch = "select city,state,bolv tbl city '%".$address."%' or state '%".$address."%' or bolv '%".$address."%'";     $ressrch = mysqli_query($cnt,"set names 'utf8'");     $ressrch = mysqli_query($cnt,"set character 'utf8'");     $ressrch = mysqli_query($cnt,"set character_set_connection = utf8");     $ressrch = mysqli_query($cnt,$querysrch);     $arry = array();     if(mysqli_num_rows($ressrch) > 0){         while($row = mysqli_fetch_assoc($ressrch)){             $addressres = $row['city']."-".$row['state']."-".$row['bolv'];             $arry[] = $row['city'];             $arry[] = $row['state'];         }     }     else     {          $arry .= "<li id='item'><a href='#' value='not found'>notfound</a></li>";     }     echo json_encode($arry);     ?> 

i want when keyup chaarcter show result , when select li tag show me value tag in jquery please me

i think code works fine forget add id on anchor tag while appending on ul. if append more 1 anchor tag should use class because there can't 2 anchor tag same id make conflict. or can use onclick attribute on anchor tag

append anchor tag this

var optionli = "<li id='item'><a href='#' value='"+res+"' onclick='show_value()'>"+city+"-"+state+"</a></li>"; 

and js function

function show_value(){      alert($("#srchtxt").val()); } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -