jeudi 25 juin 2015

Use LIKE operator to select all checkboxes that match pattern

Hello friends: I need a little guidance.

I have an HTML form comprised of a very long list of items pulled from an array generated by a database query (it's a list of university courses). Users need to be able to select as many or as few courses as are relevant to their research: because the list can have hundreds or items I have a "select all" and a "select none" function and have added a jquery shift-select batch selector to make this as easy as possible.

However, I also want them to be able to enter some text in an input box and click APPLY to select all checkboxes where the label text pattern matches using a LIKE operator (i.e., if they want all MATH courses, or all courses of level 2xx). The project is using PHP and JavaScript/jquey/AJAX.

I know how to pull from the database based on LIKE queries, but I'm just a bit stumped as to how best loop through the generated form and target the items that are in my form. (My PHP is pretty strong, my jquery is a bit shaky).

The list of checkboxes is generated via a loop through the array with each item set up as follows:

$o .= '<input id="'.$rw[2].'_'.$rw[0].'"
type=checkbox  name="' . $rw[2].'_'. $rw[0]. '" />';
$o .= '<label for="'.$rw[2].'_'. $rw[0].'"> ' . $rw[1] . '</label>';
$o .= '</td>';

So we end up with a simple checkbox form with a LABEL FOR and the label text, and the items are all named as the array keys.

This is the HTML output for a typical item:

<tr><td><input id="110_105" type=checkbox name="110_105" />
<label for="110_105"> PHIL233</label></td></tr>

Sorry if this description is a bit long, but what I need is an idea of how to go about looping through the form's elements after it is generated to SELECT the checkbox for every item where the pattern matches.

Hope this makes sense!

Tamra




Aucun commentaire:

Enregistrer un commentaire