Changeset 2770 in /cluster/svnroot


Ignore:
Timestamp:
Oct 29, 2010 2:05:56 PM (10 years ago)
Author:
fitz
Message:

#532: generalize select-all function, add 'additional software' section

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/bccd.net/ver3/survey.php

    r2769 r2770  
    1010$left = file_get_contents("includes/left.php");
    1111
     12if (isset($_POST['submit'])) {
     13        $rightHTML = "<pre>" . print_r($_POST, true) . "</pre>";
     14} else {
    1215$page->setSlot('Head', '<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>');
    1316
    1417$js = <<<JAVASCRIPT
    1518// Select all
    16 function Check(control, form, field) {
    17         chk = document.forms[form].elements[field];
     19function Check(control, formName, table) {
     20        form = document.forms[formName];       
    1821
    19         if (typeof(chk.checked) == "boolean") {
    20                 chk.checked = control.checked;
    21         } else {
    22                 for (i = 0; i < chk.length; i++) {
    23                         chk[i].checked = control.checked;
     22        for (i = 0; i < form.elements.length; i++) {
     23                chk = form.elements[i];
     24
     25                if (chk.type == 'checkbox') {
     26                        chk.checked = control.checked;
    2427                }
    2528        }
    2629
    2730        if (control.checked)
    28                 $('#softwarelist tr.row').addClass('selected');
     31                $('#'+ table + ' tr.row').addClass('selected');
    2932        else
    30                 $('#softwarelist tr.row').removeClass('selected');
     33                $('#'+ table + ' tr.row').removeClass('selected');
    3134}
    3235
    3336 // function(s) for selecting checkbox by clicking within the row
    3437$(document).ready(function() {
    35                 $('#softwarelist tr.row')
     38                $('#bccdSoftware tr.row')
    3639                .filter(':has(:checkbox:checked)')
    3740                .addClass('selected')
     
    8891<hr>
    8992<form method="POST" action="" name="softwareList">
    90 <table id="softwarelist">
     93<table id="bccdSoftware">
    9194';
    9295
     
    9497        $rightHTML .= '
    9598        <tr class="row">
    96                 <td><input type="checkbox" name="package[]" id="'.$short.'"></td>
     99                <td><input type="checkbox" name="'.$short.'" class="bccdSoftware"></td>
    97100                <td>'.$long.'</td>
    98101        </tr>';
     
    103106                <td>
    104107                        <label for="checkAllSoftware" style="font-size: 8pt;">
    105                                 <input id="checkAllSoftware" type="checkbox" name="checkall" value="yes" onClick="Check(this, 'softwareList', 'package[]')">
     108                                <input id="checkAllSoftware" type="checkbox" name="checkall" value="yes" onClick="Check(this, 'softwareList', 'bccdSoftware')">
    106109                                Select All
    107110                        </label>
     
    112115<strong>What additional software would you like to see?</strong>
    113116<hr>
     117
     118<table id="addSoftware">
     119<tbody>
     120        <tr><td><input name="addSoft[]" style="width:150px;" type="textarea"></td></tr>
     121</tbody>
     122</table>
     123<a href="#" onClick="$('#addSoftware > tbody:last').append('<tr><td><input name=\'addSoft[]\' style=\'width:150px;\' type=\'textarea\'></td></tr>'); return false;">
     124&nbsp;+&nbsp; Add another</a>
     125<br /><br />
     126<input type="submit" name="submit" style="border: 2px solid #225B92; color: #941426; background-color: #B7C0C0;">
    114127</form>
    115128HTML;
     129}
    116130
    117131$page->setSlot('LeftContent', $left);
Note: See TracChangeset for help on using the changeset viewer.