php - Let a div get a value from a fetch-array-table row after click on a cell with jquery -


first want question related jquery replacewith data ajax after click on cell , if against rule sorry , delete post.

i tried value of cell in mysql-generated table (with fetch_array). want click on cell in same , receive value of first cell in row in div-container.

thanks several entries here found example "static" tables. this:

<table id="choose-address-table" class="ui-widget ui-widget-content">   <thead>     <tr class="ui-widget-header ">       <th>name/nr.</th>       <th>street</th>       <th>town</th>       <th>postcode</th>       <th>country</th>       <th>options</th>     </tr>   </thead>   <tbody>     <tr>       <td class="nr"><span>50</span>        </td>       <td>some street 1</td>       <td>glasgow</td>       <td>g0 0xx</td>       <td>united kingdom</td>       <td class="use-address">         use       </td>     </tr>     <tr>       <td id="chip" class="nr">49</td>       <td>some street 2</td>       <td>glasgow</td>       <td>g0 0xx</td>       <td>united kingdom</td>       <td>           <button type="button" class="use-address">use</button>       </td>     </tr>   </tbody> </table> <br><br> <div id="glasgow">hello</div>  

and

$("#chip").click(function () {   var scotland = $(this).closest("tr").find(".nr").text();    $("#glasgow").html(scotland); }); 

http://jsfiddle.net/fndvl/231/

works fine. insert file, php, , table data mysql.

this code:

<html> <head> <script type="text/javascript" charset="utf-8" src="http://code.jquery.com/jquery-latest.min.js"></script> <script> $(".information").click(function () {   var rodney = $(this).closest("tr").find(".nr").text();    $(".clicked_info").html(rodney); }); </script>   <link rel="stylesheet" type="text/css" href="css/style.css"> </head> <body> <? $con = mysqli_connect('localhost','root','','boerse'); $sql="select short, name markets";         $result = mysqli_query($con,$sql);  ?>         <div class="markets">  <? echo "<table> <thead border='0'> <tr> <th>index</th> <th>name</th> </tr> </thead> <tbody border='1'>"; while($row = mysqli_fetch_array($result))   {   echo "<tr>";   echo "<td class='nr'>" . $row['short'] . "</td>";   echo "<td>" . $row['name'] . "</td>";   echo "<td class='information'>use</td>";   echo "</tr>";   } echo "</tbody></table>"; ?> <div class="clicked_info">hello</div>       </div> <br><br>   </body> </html> 

now problem can click on td class information, div class 'clicked_info' doesn't change. did in fiddle. went wrong? or problem? must have mysql-matter. why?

this way want check if got content cell , can continue working (as seen in post before).

maybe can help. , again sorry if break rules here.

thank everyone.

you need wrap code in document-ready handler

$(document).ready(function () {     $(".information").click(function () {         var rodney = $(this).closest("tr").find(".nr").text();         $(".clicked_info").html(rodney);     }); }); 

currently when script executes there no $(".information") event not binded properly.

or

move script @ bottom of page. like

<script> $(".information").click(function () {   var rodney = $(this).closest("tr").find(".nr").text();    $(".clicked_info").html(rodney); }); </script> </body> 

or

you can use event-delegation

$(document).on("click", ".information",function () {   var rodney = $(this).closest("tr").find(".nr").text();    $(".clicked_info").html(rodney); }); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -