Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:21:41+00:00 2026-06-08T14:21:41+00:00

<a class=checkModelButton href=check.php>Check</a> <div id=model_list></div> include jquery and function deleteRow(): jQuery(‘.checkModelButton’).click(function(event){ event.preventDefault(); var url

  • 0
<a class="checkModelButton" href="check.php">Check</a>
<div id="model_list"></div>

include jquery and function deleteRow():

jQuery('.checkModelButton').click(function(event){
   event.preventDefault();
   var url = jQuery(this).attr('href');
   jQuery.ajax({
         type: 'get',
         cache: false,
         url: url,
         success: function(html){
             jQuery('#model_list').html(html);
         }
   });
});
function deleteRow(id) {
    try {
        var table = document.getElementById('model_list');
        var rowCount = table.rows.length;
        for(var i=0; i<rowCount; i++) {
            var row = table.rows[i];
            var chkbox = row.cells[0].childNodes[0];
            if(null != chkbox && true == chkbox.checked) {
                table.deleteRow(i);
                rowCount--;
                i--;
            }
        } 
        jQuery("input[type=checkbox]:checked").each(function() { 
            jQuery(this).parents("tr").remove(); 
        });    

    } catch(e) {
        alert(e);
    }
}

in check.php return html is:

<input type="button" value="Delete Row" onclick="deleteRow('model_list')" />
<table id="model_list">
   <thead>
      <tr>
        <th>#</th>
        <th>Name</th>
      </tr>
   </thead> 
   <tbody>
      <tr>
        <td><input type="checkbox" value="1" name="model_id[]" class="item"></td>
        <td>Nokia N71</td>
      </tr>
   </tbody>
</table>

After loadding ajax, I checked on form input and click button Delete Row, but error can’t delete this row And error is alert(Table model_list is empty), how to fix it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:21:43+00:00Added an answer on June 8, 2026 at 2:21 pm

    jQuery has really simplified the selection process for us and also provided a lot of fail-safes that JavaScript doesn’t offer without a try/catch block.
    Since you’re already using jQuery, you can really simplify your deleteRow() function by doing the following:

    function deleteRow(id) {   // the id variable is unnecessary and can be removed
        // Grab all the rows in the table (the > sign targets the elements directly inside the current one (not cascading)
        var rows = jQuery("#model_list > tbody > tr");
        // Iterate through the rows
        jQuery(rows).each(function(key, value) {
            // Look inside each row for a checked checkbox
            if (jQuery(this).find("input:checkbox[checked='checked']").length > 0) {
                // If one is found, then remove the whole row (jQuery(this) refers to the current row
                jQuery(this).remove();
            }
        });
    }
    

    To make the example above work, I created a temporary table in the same file. Since you are dynamically loading the table rows with data, this should function similar to the static sample below:

    <input type="button" value="Delete Row" onclick="deleteRow('model_list')" />
    <table id="model_list">
        <thead>
            <tr>
                <th>#</th>
                <th>Name</th>
            </tr>
        </thead> 
        <tbody>
            <tr>
                <td><input type="checkbox" value="1" name="model_id[]" class="item"></td>
                <td>Nokia N71</td>
            </tr>
            <tr>
                <td><input type="checkbox" value="2" name="model_id[]" class="item"></td>
                <td>Nokia N72</td>
            </tr>
            <tr>
                <td><input type="checkbox" value="3" name="model_id[]" class="item"></td>
                <td>Nokia N73</td>
            </tr>
        </tbody>
    </table>
    

    Please let me know if this is helpful or if you have any other questions. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<a class=checkModelButton href=addrow.php>ADD ROW</a> <table> <thead> <th>Name</th> </thead> <tboby id=model_row> <tr>Nokia N70</tr> </tbody> </table>
class LinkedList{ private $first; public function Merge(LinkedList $ll){ //We can't access $ll->first for merging
class Api::StoresController < ApplicationController respond_to :json def index @stores = Store.all(:include => :products) respond_with
class Score { var $score; var $name; var $dept; var $date; function Score($score, $name,
class SignUp { var $pass; var $repass; var $eMail; var $userName; function __construct($p,$rep,$uName,$mail) {
class MyClass { var $lambda; function __construct() { $this->lambda = function() {echo 'hello world';};
class CartesianProduct include Enumerable # your code here end #Examples of use c =
class Registration_model extends CI_Model { function __construct() { parent::__construct(); } function check_email_availability($email) { $sql
class Widget; std::vector< std::shared_ptr<Widget> > container class Criterium { public: bool operator()(const Widget& left,
Class 1 private void checkDuplicateCustomer(BulkCustomerVO bulkCustomerVO) { PagedDuplicateCustomerVO duplicateCustomerVO = new PagedDuplicateCustomerVO(); duplicateCustomerVO.setCustomer(bulkCustomerVO.getCustomerVO()); duplicateCustomerVO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.