Changeset 54


Ignore:
Timestamp:
07/26/11 15:33:20 (14 years ago)
Author:
fpvanagthoven
Message:

Integer input checking in SurveyTool?. But o no! Some javascript dubbele code. >_<

Location:
Dev/trunk/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/SurveyCreationTool.php

    r53 r54  
    374374                }
    375375            }
    376                                            
    377                                                                                                                                                                                                                                                                                                                                                                                                                                            
     376                                                                                                                                                                                                                                                                                                                                                                                                                             
    378377        </script>
    379378        <?php
  • Dev/trunk/classes/SurveyTool.php

    r52 r54  
    1313        $this->survey = $survey;
    1414
     15        $this->javascript();
    1516        $this->init();
     17    }
     18
     19    private function javascript() {
     20        ?>
     21        <script type="text/javascript">
     22                        /* --- input checking --- */
     23            function checksPassed(form)
     24            {
     25                for (var i = 0; i < form.length; i++)
     26                {
     27                    if (form.elements[i].checkPassed == 'no')
     28                        return false;
     29                }
     30                return true;
     31            }
     32                   
     33            function checkInt(input)
     34            {
     35                input.style.borderWidth = '1px' ;
     36                var value = input.value;
     37                if (isNaN(value))
     38                {
     39                    input.style.borderColor = 'red';
     40                    input.checkPassed = 'no';
     41                }
     42                else
     43                {
     44                    input.style.border = '1px solid #abadb3';
     45                    input.checkPassed = null;
     46                }
     47            }
     48        </script>
     49        <?php
    1650    }
    1751
    1852    private function init() {
    1953        ?>
    20         <form action="" method="post">
     54        <form name="survey" action="" onsubmit="return checksPassed(this)" method="post">
    2155            <?php
    2256            $this->displayTitle();
     
    78112            case 'int':
    79113                ?>
    80                 <input type="text" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="" class="intBox"/>
     114                <input type="text" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="" onchange="checkInt(this)" class="intBox"/>
    81115                <?php
    82116                break;
     
    101135                <?php
    102136                for ($i = 1; $i < $question->answers[3] + 1; $i++) {
    103                     ?><input type="radio" class="scaleRadio" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="<?php echo $i;?>"/><?php } ?>
     137                    ?><input type="radio" class="scaleRadio" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="<?php echo $i; ?>"/><?php } ?>
    104138                <div class="scaleLabel"><?php echo $question->answers[2]; ?></div>
    105139                <?php
Note: See TracChangeset for help on using the changeset viewer.