javascript - Remove TR from Table -


i'm drawning table via php echo, containing data sql query. it's cart script. when customer click remove item cart, want remove tr table. i'll call javascript function 'removefromcart' passing item id , row index. function remove item in cart sql, , row index delete tr table. here how i'm trying do:

        <?php             $uid = mysql_real_escape_string($_session['userlogged']);             $query = mysql_query("select id, info cart username = '$uid'");             while($row = mysql_fetch_array($query))             {                 echo '<tr id="ordertable"> <td> '.htmlspecialchars($row["info"], ent_quotes, 'utf-8').' </td>';                 $id = $row['id'];                 $newquery = mysql_query("select name, date, country, flag, code, med, price products id = '$id'");                 while($newrow = mysql_fetch_array($newquery))                 {                     echo '<td> '.htmlspecialchars($newrow["name"], ent_quotes, 'utf-8').' </td>';                        echo '<td> '.htmlspecialchars($newrow["date"], ent_quotes, 'utf-8').' </td>';                     echo '<td> '.htmlspecialchars($newrow["country"], ent_quotes, 'utf-8').' </td>';                     echo '<td> '.htmlspecialchars($newrow["flag"], ent_quotes, 'utf-8').' </td>';                     echo '<td> '.htmlspecialchars($newrow["code"], ent_quotes, 'utf-8').' </td>';                     echo '<td> '.htmlspecialchars($newrow["med"], ent_quotes, 'utf-8').' </td>';                     echo '<td> '.htmlspecialchars($newrow["price"], ent_quotes, 'utf-8').' </td>';                     echo '<td><label><a href="javascript:buyfromcart('.htmlspecialchars($row['id'], ent_quotes, 'utf-8').')">                                         <b><img src="/img/buy.png" /></b></a></label>                                         <label>                                         <script>                                             var x = document.getelementbyid("ordertable").rowindex;         document.write(\'<a href="javascript:removefromcart('.htmlspecialchars($row['id'], ent_quotes, 'utf-8').', \'+ x +\')"><b><img src="/img/cancel.png"/></b></a></label> </td> </tr>\') </script>';                 }             }            ?>         </table>         </div> 

but link in href cancel.png image is:

javascript:removefromcart(3, 1) 

where 3 id product (ok), second parameter, every tr in table, 1... why it's not getting current row index tr?

the html output generated is:

<html> <head>     <link rel="stylesheet" href="./css/style.css">     <title>shop.su</title>     <script type="text/javascript">      function load(url) {     var xmlhttp;      if (window.xmlhttprequest) {         // code ie7+, firefox, chrome, opera, safari         xmlhttp = new xmlhttprequest();     } else {         // code ie6, ie5         xmlhttp = new activexobject('microsoft.xmlhttp');     }      xmlhttp.onreadystatechange = function() {         if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {            document.getelementbyid('cart').innerhtml = 'your orders ('+xmlhttp.responsetext+')';         }     }      xmlhttp.open('get', url, true);     xmlhttp.send();     }      function addtocart(id)     {         document.getelementbyid('add'+id).innerhtml='<b>added!</b>';         load('/cart.php?addtocart&dump='+id);     }      function removefromcart(id, x)     {         alert("row index is: " + x.rowindex);        }     </script> </head> <body id="home">     <div id='cssmenu'> <ul>    <li id="homeicon" class='active'><a href='?news'><span>news</span></a></li>    <li id="ordersicon"><a href='?orders'><span id="cart">your orders (11)</span></a></li>    <li id="ticketicon" class='last'><a href='?tickets'><span>tickets</span></a></li> </ul> </div>    <div id="container">         <p class="orderpage"> current cart items:: </p> <div class="resultstable" >                 <table >                 <tr>                 <td>                     type                 </td>                 <td>                     name                 </td>                 <td>                     date                 </td>                 <td>                     country                 </td>                 <td>                     flag                 </td>                 <td>                     code                 </td>                 <td>                     med.                 </td>                 <td>                     price                 </td>                 <td>                     buy                 </td>                 </tr>                 <tr id="ordertable"> <td> mirror </td><td> newname </td><td> 456789 </td><td> usa </td><td> visa </td><td> 101 </td><td> 1409 </td><td> 10.00 </td><td><label><a href="javascript:buyfromcart(3)">                                                 <b><img src="/img/buy.png" /></b></a></label>                                                 <label>                                                 <script>                                                     var x = document.getelementbyid("ordertable").rowindex;                 document.write('<a href="javascript:removefromcart(3, '+ x +')"><b><img src="/img/cancel.png"/></b></a></label> </td> </tr>') </script><tr id="ordertable"> <td> track </td><td> new base123123 </td><td> 456789 </td><td> brazil </td><td> test </td><td> 101 </td><td> 1409 </td><td> 10.00 </td><td><label><a href="javascript:buyfromcart(4)">                                                 <b><img src="/img/buy.png" /></b></a></label>                </table>                 </div>    </div> </body> </html> 

i'd like:

while($row = mysql_fetch_array($query)) {    cont++;    echo '<tr id="myrow' . cont . '"> 

and then:

javascript:removefromcart('. $row['id'] .', ' . $cont ')... 

btw, think should use pdo


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -