Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Anyone know how to code a Select All checkbox?


Guest

Recommended Posts

Using 2.3.4.1 CE (Frozen? - maybe?) and PHP 7.0

I recently installed a contribution called Keyword Search Report.  Had to clean it up a bit as it's rather old, but this is what it looks like in my test site.

930321693_keywordsselect.PNG.f8cb34c614b306ea08b54356a8692cd5.PNG

There is no checkbox to Select All and then delete which is an issue in my live site.  The report fills up rather briskly and it's annoying having to select each keyword in the report one-at-a-time for deletion.  Does anyone know of a way to create a Select All field (in my blue X area above) that would make life a little simpler?  Maybe an online tutorial or something you could point me to?  I've Googled it quite a bit and am pretty stuck now.  Thank You!

- Andrea

 

Link to comment
Share on other sites

Hi Andrea

Try this following;

Open your admin/stats_keywords.php file

FIND

<!-- bof function delete -->
<td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_DELETE; ?></td>
<!-- eof function delete -->

REPLACE WITH

<!-- bof function delete -->
<td class="dataTableHeadingContent" align="left"><input type="checkbox" onClick="toggle(this)" /> Toggle All<br/></td>
<!-- eof function delete -->


AT THE VERY END OF THE FILE ADD

<script>
function toggle(source) {
  checkboxes = document.getElementsByName('update_keyword_list[]');
  for(var i=0, n=checkboxes.length;i<n;i++) {
    checkboxes[i].checked = source.checked;
  }
}
</script>

To keep everything nicely aligned

FIND

<!-- bof function delete -->
<td class="dataTableContent" align="center">
<?php echo tep_draw_checkbox_field('update_keyword_list[]', $keywords['search_text']); ?>
</td>
<!-- eof function delete -->

REPLACE WITH

<!-- bof function delete -->
<td class="dataTableContent" align="left">
<?php echo tep_draw_checkbox_field('update_keyword_list[]', $keywords['search_text']); ?>
</td>
<!-- eof function delete -->

 

Hope that helps.

Link to comment
Share on other sites

Indeed, a "Select All" button or checkbox would be useful for lists that could get quite long. I think a "Select All" checkbox is the usual way of doing things. If it's checked (selected), your code loops (in JavaScript) through all the child boxes and checks them. If it's unchecked (deselected), you would go through and uncheck all of them. Note that strictly speaking, this is not proper checkbox behavior, as there is immediate effect rather than waiting for the form to be submitted, but it's a common-enough idiom that it shouldn't cause confusion. A button with a label that toggles between "Select All" and "Clear All" could do the same thing.

I don't know if it's that useful to toggle the existing state of the child boxes... it could be done, but I can't think of any reason to add it, unless the boxes are presented partially pre-checked (from the database, or something) and it's useful to flip all of the choices. Anyway, that would require a separate button for that action.

I haven't looked at the code, but if there is a function to build such a screen section (multiple checkboxes), it would be useful in general to add a "Select All" checkbox and JS.

Link to comment
Share on other sites

9 hours ago, Tsimi said:

Hope that helps.

Your help is invaluable, as always.  Works perfectly and looks great!  So much easier to take care of this way.

Thanks, @Tsimi !  Thanks, @MrPhil !

- Andrea

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...