jquery - Get button value printed by php and process them via javascript -


i have dynamic table results database printed.

<table id="table" class="table datatable-responsive">     <thead>         <tr class="bg-teal">             <th>#</th>             <th>datum & vrijeme</th>             <th>stavka</th>                                                              <th><center>izabrana količina</center></th>             <th><center><i class="icon-pencil"></i></center></th>             <th><center><i class="icon-bin"></i></center></th>         </tr>     </thead>     <tbody>         <?php              $i = 1;             while ($r=$q->fetch()) {                 $a = 0;                 $a += 1;                  $id = $r['id'];                 $datum = $r['datum'];                                                            $time = date("h:i:s",strtotime($datum));                 $time2 = date("d/m/y",strtotime($datum));                 $stavka = $r['stavka'];                                                          $kolicina = $r['kolicina'];          ?>         <tr>             <td><?php echo $i; $i++; ?></td>             <td><?php echo $time2 .' & '.$time; ?></td>             <td><?php echo $stavka; ?></td>             <td class="nr"><center><?php echo $kolicina; ?></center></td>             <td><center><button type="button" value="<?php echo $id?>"  name="izmjena" onclick="showdiv()"><i class="icon-pencil text-danger"></i></center></button>             </td>                                                                <td><center><button type="submit" value="<?php echo $id ;?>" name="brisi" class="icon-bin text-danger"></button></center></td>         </tr>          <?php } ?>     </tbody>     <!--<a onclick="window.open('edit/korpa.php?id= <?=$r['id']?>','e-cart','width=800,height=500,left=0,top=100,screenx=0,screeny=100,menubar=yes,scrollbars=yes')"> --> </table> 

in table have button editing "kolicina". once click on button in row, needs open div.

in div, need pass values , print them using js. once that, need save in db php

once click on button div below shows (it works).

<div class="col-lg-9" id="izmjenadiv" style="display:none;" >                                        <div class="panel panel-flat">               <table class="table table-bordered">                                                         <tr>                 <th class="">količina</th>                 <td class=""><input type="text" id="id" value="" class="form-control text-info border-info"></td>                 <td class=""><input type="text" id="kolicina" name="kolicina" placeholder="upišite novu količinu" class="form-control text-danger border-danger"></td>                 <td class="">                     <select class="form-control" id="mjera" name="mjera">                         <option value="kg">kg </option>                          <option value="kom">kom </option>                     </select>                 </td>             </tr>                                            </table><hr/>            <div class="pull-right">             <button type="button" class="btn btn-success btn-sm" onclick="savechanges()"> snimi <i class="icon-play3 position-right"></i></button>&nbsp;&nbsp;&nbsp;                                                 </div>         <br/><br/><br/>      </div>           </div> 

i need make script willl 2 values row, 1 button 1 row "kolicina". need print values in div shows on click. made script automatically closes div want open.

<script>     function showdiv() {         document.getelementbyid('izmjenadiv').style.display = "block";              var y = $(object).parent("center").parent("td").parent("tr").find(".nr center").text();             var x = $(object).attr("value");                      window.location.href = "korpa.php?w1=" + x + "&w2=" + y;        } </script> 

any advice appreciated

pass reference of td tag argument in showdiv() function. change html:

<td><center><button type="button" value="<?php echo $id?>"  name="izmjena" onclick="showdiv(this)"><i class="icon-pencil text-danger"></i></center></button>                 </td>   

javascript:

function showdiv(obj) {         document.getelementbyid('izmjenadiv').style.display = "block";        var id = $(obj).parent("center").parenrt("td").parent("tr").find(".nr center").text();      } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -