Note that there are some explanatory texts on larger screens.

plurals
  1. POMy Javascript delete code is not working. Error "TypeError: checkBox is undefined @ javascripts/js/delete.js:5"
    primarykey
    data
    text
    <p>I cannot figure out why this isn't working, it was working fine last week and now it isn't. I figured I must have mistakenly changed something, but after going over the whole thing, I couldn't find anything. So, I'm wondering now if my code wasn't very good in the first place. Here is the <code>delete.js</code> file:</p> <pre><code>function deleterecord(form) { var checkBox = document.edit.checkbox; var lenBox = checkBox.length; var foundBox = false; while( lenBox--&gt; 0 ) { if( checkBox[lenBox].checked === true ) { foundBox = true; break; } } if( !foundBox ) { alert("Please select a record to delete"); return; } var r=confirm("Once deleted, these records are gone forever.\n\n Are you SURE you want to proceed? "); if (r==true) { form.submit(); } else { alert("Phew! That was close!\n\n No records were deleted."); window.location.reload(true); } return; } </code></pre> <p>...and here is the html form:</p> <pre><code>&lt;form action="process_delete.php" method="post" id="edit" name="edit"&gt; &lt;table cellpadding="4px" cellspacing="2px" border="1"&gt; &lt;tr align="center"&gt; &lt;td&gt;Aircraft Reg&lt;/td&gt; &lt;td&gt;Date Installed&lt;/td&gt; &lt;td&gt;Prefix&lt;/td&gt; &lt;td&gt;Part Number&lt;/td&gt; &lt;td&gt;Flight Control&lt;/td&gt; &lt;td&gt;Lat Position&lt;/td&gt; &lt;td&gt;Long Position&lt;/td&gt; &lt;td&gt;Vert Position&lt;/td&gt; &lt;td&gt;Location&lt;/td&gt; &lt;td&gt;Material&lt;/td&gt; &lt;td&gt;OEM/PMA&lt;/td&gt; &lt;td&gt;Select&lt;/td&gt; &lt;/tr&gt; $result = mysql_query("SELECT * FROM installed $filter ORDER BY aircraft_reg , part_number, date_installed ASC"); $pagerow = mysql_num_rows($result); if ($pagerow &gt; 0 ) { while($row = mysql_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" . $row['aircraft_reg'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['date_installed'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['prefix'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['part_number'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['flight_control'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['lat_position'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['long_position'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['vert_position'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['location'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['material'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['oempma'] . "&lt;/td&gt;"; echo "&lt;td align=\"center\"&gt;&lt;input type=\"checkbox\" selected=\"\" id=\"checkbox\" name=\"check_list[]\" value=\"" . $row['id'] . "\"&gt;&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;tr align=\"center\"&gt;"; echo "&lt;td colspan=\"12\"&gt;&lt;input type=\"button\" value=\"Delete Selected\" style=\"width:150px; height:30px;\" onClick=\"deleterecord(form)\"&gt;&lt;/td&gt;"; echo "&lt;/tr&gt;"; } else { echo "&lt;tr&gt;&lt;td align=\"center\" colspan=\"12\"&gt;&lt;h2&gt;No Records To Display&lt;/h2&gt;&lt;/td&gt;&lt;/tr&gt;"; } &lt;/table&gt; &lt;/form&gt; </code></pre> <p>I have tried different variations of the <code>document.edit.checkbox;</code> such as <code>document.getElementById["edit"].checkbox;</code> or <code>document.getElementById["checkbox"];</code> but I'm not able to get it working. Here is a <a href="http://jsfiddle.net/FoxRocks/hvjZH/" rel="nofollow">jsfiddle</a> if that helps, and I removed the php bits and entered some sample values instead. As you can probably tell I'm very new to Javascript, but I'm trying my best and would really appreciate any guidance you could provide.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload