Changeset 20


Ignore:
Timestamp:
07/18/11 17:32:16 (14 years ago)
Author:
fpvanagthoven
Message:

Last option can now be removed.

File:
1 edited

Legend:

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

    r19 r20  
    2929        <script type="text/javascript">
    3030            var questionCount = 1;           
    31                                                                                                            
     31                                                                                                                   
    3232            function getNewQuestion()
    3333            {
     
    5252                    "<div id='answersDiv" + questionCount + "'></div>" +
    5353                    "</div>";
    54                                                                                                        
     54                                                                                                               
    5555                questionDiv.innerHTML = htmlStr;
    56                                                                                                        
     56                                                                                                               
    5757                return questionDiv;
    5858            }
    59                                                                                                            
     59                                                                                                                   
    6060            function handleFocus(input)
    6161            {
     
    6767                }
    6868            }
    69                                                                                                                                            
     69                                                                                                                                                   
    7070            function handleBlur(input)
    7171            {       
    7272                var surveyTitle = document.getElementById('surveyTitle');
    7373                var surveyDescription = document.getElementById('surveyDescription');
    74                                                                                                                            
     74                                                                                                                                   
    7575                if (input.value == "")
    7676                {
    7777                    input.style.color = "gray";
    7878                    input.clicked = null;
    79                                                                                                                                                    
     79                                                                                                                                                           
    8080                    if (input == surveyTitle)
    8181                    {
     
    8888                }                           
    8989            }
    90                                                                                            
     90                                                                                                   
    9191            function handleType(select)
    9292            {
     
    9595                answersDiv.answerCount = 1;
    9696                answersDiv.clicked = null;
    97                                                
     97                                                       
    9898                switch (type) {
    9999                    case 'mc':
    100100                        answersDiv.innerHTML = "";
    101101                        addOption(select.id);
    102                                                                                
     102                                                                                       
    103103                        break;
    104104                    case 'text':
     
    124124
    125125            }
     126                                                                                   
    126127                                                                           
    127                                                                    
    128128            function addOption(questionNumber)
    129129            {       
     
    132132                var answerDiv = document.createElement("div");
    133133                answerDiv.className = "answerDiv";
    134                                                                        
     134                                                                               
    135135                var htmlStr = "<input type='text' name='q" +
    136136                    questionNumber + "ans" + answerCount + "' value='Option " + answerCount + "' />";
    137                                                
     137                                                       
    138138                if (answersDiv.clicked == null)
    139139                {
    140140                    htmlStr += "<input type='button' id='addOpt'"
    141                         + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />";
     141                        + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" +
     142                        "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />";
     143                           
    142144                    answersDiv.clicked = true;
    143145                }
    144                                                                                
     146                                                                                      
    145147                answerDiv.innerHTML = htmlStr;
    146                                                                                
     148                       
     149                answerDiv.prev = answersDiv.lastAnswer; //singly linked list
     150                answersDiv.lastAnswer = answerDiv;
     151                                                                                       
    147152                answersDiv.appendChild(answerDiv);
    148153                answersDiv.answerCount++;
    149154            }
    150                                    
     155                   
     156            function removeOption(questionNumber)
     157            {
     158                var answersDiv = document.getElementById("answersDiv" + questionNumber);
     159                       
     160                if (answersDiv.lastAnswer.prev != null)
     161                {
     162                    answersDiv.removeChild(answersDiv.lastAnswer);
     163                    answersDiv.lastAnswer = answersDiv.lastAnswer.prev;
     164                    answersDiv.answerCount--;
     165                }
     166            }
     167                                           
    151168            function minMax(questionNumber)
    152169            {
    153170                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    154                                        
     171                                              
    155172                var answerDiv = document.createElement("div");
    156173                answerDiv.className = "answerDiv";
    157174                answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' name='min" + questionNumber + "' />" +
    158175                    "<label for='max'>Max</label><input type='text' name='max" + questionNumber + "' />";
    159                                    
     176                                          
    160177                answersDiv.appendChild(answerDiv);
    161178            } 
    162                                    
     179                                           
    163180            function minMaxIncr(questionNumber)
    164181            {
    165182                minMax(questionNumber);
    166183                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    167                                        
     184                                              
    168185                var answerDiv = document.createElement("div");
    169186                answerDiv.className = "answerDiv";
    170187                answerDiv.innerHTML = "<label for='incr'>Increment by</label><input type='text' name='incr" + questionNumber + "' />";
    171                                    
     188                                          
    172189                answersDiv.appendChild(answerDiv);
    173190            }         
    174                                                                                          
    175191                                                                                                 
     192                                                                                                         
    176193            function addQuestion()
    177194            {
    178195                var questionsDiv = document.getElementById('questionsDiv');
    179196                var newQuestion = getNewQuestion();
    180                                
     197                                       
    181198
    182199                newQuestion.prev = document.lastQuestion;
     
    186203                questionCount++;
    187204            }
    188                            
     205                                   
    189206            function removeLastQuestion()
    190207            {
    191208                var questionsDiv = document.getElementById('questionsDiv');
    192                                
     209                                       
    193210                if (document.lastQuestion.prev != null)
    194211                {
     
    202219                }               
    203220            }
    204                          
    205                                    
    206                                                                                                                                                                                                                    
     221                                 
     222                                           
     223                                                                                                                                                                                                                           
    207224        </script>
    208225        <?php
Note: See TracChangeset for help on using the changeset viewer.