Changeset 17 for Dev/trunk


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

Multiple choice option functional.

Location:
Dev/trunk
Files:
4 edited

Legend:

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

    r10 r17  
    1717        <form action="surveycreation.php" method="post">
    1818
    19             <input id="newSurveyButton" type="submit" name="btnlogin" value="Create new survey" class="button" />
     19            <input id="newSurveyButton" type="submit" name="btnlogin" value="Create new survey" class="surveyButton" />
    2020
    2121        </form>
  • Dev/trunk/classes/SurveyCreationTool.php

    r11 r17  
    1212        SurveyCreationTool::javascript();
    1313        ?>
     14
    1415        <div id="surveyCreation"><form action="submitsurvey.php" method="post">
    1516                <?php
     
    1718                SurveyCreationTool::descriptionBox();
    1819                SurveyCreationTool::questionCreationForm();
     20                SurveyCreationTool::addQuestionButton();
    1921                SurveyCreationTool::submitButton();
    2022                ?></form></div>
     
    2527        ?>
    2628        <script type="text/javascript">
    27                                                                                    
     29            var questionCount = 1;           
     30                                                                           
     31            function getNewQuestion()
     32            {
     33                var questionDiv = document.createElement("div");
     34                var htmlStr =
     35                    "<div id='question" + questionCount + "' class='question'>" +
     36                    "<table class='questionTable'>" +
     37                    "<th>Question " + questionCount + "</th>" +
     38                    "<tr><td><label for='questionTitle'>Title</label></td>" +
     39                    "<td><input type='text' class='questionTitle' name='questionTitle" + questionCount + "' size='30' value='Untitled Question' /></td></tr>" +
     40                    "<tr><td><label for='questionDescription'>Description</label></td>" +
     41                    "<td><input type='text' class='questionDescription' name='questionDescription" + questionCount + "' size='60' value='Write a question description here.' /></td>" +
     42                    "<tr><td><label for='questionType'>Answer type</label></td>" +
     43                    "<td><select id='" + questionCount + "' name='questionType" + questionCount + "' onchange='handleType(this)'><br />"+
     44                    "<option value='text' selected='selected'>Text</option>" +
     45                    "<option value='multipleChoice'>Multiple choice</option>" +
     46                    "<option value='checkboxes'>Checkboxes</option>" +
     47                    "<option value='scale'>Scale</option>" +
     48                    "<option value='grid'>Grid</option>" +
     49                    "</select></td></tr>" +
     50                    "</table>" +
     51                    "<div id='answersDiv" + questionCount + "'></div>" +
     52                    "</div>";
     53                                                                       
     54                questionDiv.innerHTML = htmlStr;
     55                                                                       
     56                return questionDiv;
     57            }
     58                                                                           
    2859            function handleFocus(input)
    2960            {
     
    3566                }
    3667            }
    37            
     68                                                                                                           
    3869            function handleBlur(input)
    39             {
     70            {       
     71                var surveyTitle = document.getElementById('surveyTitle');
     72                var surveyDescription = document.getElementById('surveyDescription');
     73                                                                                           
    4074                if (input.value == "")
    4175                {
    4276                    input.style.color = "gray";
    43                     input.value = "Untitled Survey";
    4477                    input.clicked = null;
     78                                                                                                                   
     79                    if (input == surveyTitle)
     80                    {
     81                        input.value = "Untitled Survey";
     82                    }
     83                    else if (input == surveyDescription)
     84                    {
     85                        input.value = "Write a helpful description for this survey here.";
     86                    }
     87                }                           
     88            }
     89                                                           
     90            function handleType(select)
     91            {
     92                var type = select.valueOf().value;
     93                var answersDiv = document.getElementById("answersDiv" +  select.id);
     94                answersDiv.answerCount = 1;
     95                answersDiv.clicked = null;
     96               
     97                switch (type) {
     98                    case 'multipleChoice':
     99                        answersDiv.innerHTML = "";
     100                        addOption(select.id);
     101                                               
     102                        break;
     103                    case 'text':
     104                        answersDiv.innerHTML = "";
     105                       
     106                        break;
     107                    case 'checkboxes':
     108                        answersDiv.innerHTML = "";                                               
     109                        break;
     110                    case 'scale':
     111                        answersDiv.innerHTML = "";                                               
     112                        break;
     113                    case 'grid':
     114                        answersDiv.innerHTML = "";                                               
     115                        break;
     116                    default:
     117                        break;
    45118                }
     119
    46120            }
    47                                                                                    
     121                                           
     122                                   
     123            function addOption(questionNumber)
     124            {       
     125                var answersDiv = document.getElementById("answersDiv" + questionNumber);
     126                var answerCount = answersDiv.answerCount;
     127                var answerDiv = document.createElement("div");
     128                answerDiv.className = "answerDiv";
     129                                       
     130                var htmlStr = "<input type='text' name='q" +
     131                    questionNumber + "ans" + answerCount + "' value='Option " + answerCount + "' />";
     132               
     133                if (answersDiv.clicked == null)
     134                {
     135                    htmlStr += "<input type='button' id='addOpt'"
     136                        + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />";
     137                    answersDiv.clicked = true;
     138                }
     139                                               
     140                answerDiv.innerHTML = htmlStr;
     141                                               
     142                answersDiv.appendChild(answerDiv);
     143                answersDiv.answerCount++;
     144            }
     145                                           
     146                                                         
     147            function addQuestion()
     148            {
     149                var questionsDiv = document.getElementById('questionsDiv');
     150                var newQuestion = getNewQuestion();
     151                                                                       
     152                questionsDiv.appendChild(newQuestion);
     153                questionCount++;
     154            }
     155                                                                                                                                                                                   
    48156        </script>
    49157        <?php
     
    52160    private static function titleBox() {
    53161        ?>
    54         <input type="text" name="surveyTitle" value="Untitled Survey" id="surveyTitle" size="30" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
     162        <input type="text" id="surveyTitle" name="surveyTitle" value="Untitled Survey" size="30" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
    55163        <?php
    56164    }
     
    58166    private static function descriptionBox() {
    59167        ?>
    60         <textarea id="surveyDescription" rows="3" cols="80" name="surveyDescription">Write a helpful description for this survey here.</textarea>
     168        <textarea id="surveyDescription" rows="3" cols="80" name="surveyDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)">Write a helpful description for this survey here.</textarea>
    61169        <?php
    62170    }
    63171
    64172    private static function questionCreationForm() {
    65 
    66         SurveyCreationTool::addQuestionButton();
     173        ?>
     174        <div id='questionsDiv'>
     175        </div>
     176        <script type="text/javascript"> addQuestion(); </script>
     177        <?php
    67178    }
    68179
    69180    private static function addQuestionButton() {
    70        
     181        ?>
     182        <input id="addQuestionButton" type="button" onclick="addQuestion()" value="Add New Question" class="surveyButton" />
     183        <?php
    71184    }
    72185
     
    74187        ?>
    75188        <input type="submit" name="submitSurvey"
    76                value="Submit Survey!" id="submitSurvey"/>
     189               value="Submit Survey!" class="surveyButton" id="submitSurvey"/>
    77190        <?php
    78191    }
  • Dev/trunk/css/style.css

    r11 r17  
    2525#wrapper {
    2626    width: 80%;
     27    min-width: 570px;
    2728    margin: auto;
    2829}
     
    9697}
    9798
     99#questionsDiv {
     100    margin-top: 2em;
     101}
     102
    98103#submitSurvey {
    99104    display: block;
     
    102107    margin-top: 2em;
    103108}
     109
     110#addQuestionButton {
     111    width: 20em;
     112}
     113
     114#addOpt {
     115    margin-left: 1em;
     116}
     117
     118.surveyButton {
     119    margin-top: 1em;
     120    color: gray;
     121    background-color: #fff;
     122    border: 1px solid #ddd;
     123    -moz-border-radius: 8px;
     124    border-radius: 8px;
     125    -moz-box-shadow: 1px 1px 1px #555;
     126    -webkit-box-shadow: 1px 1px 1px #555;
     127    box-shadow: 1px 1px 1px #555;
     128}
     129
     130.surveyButton:hover {
     131    background-color: white;
     132    color: #333;
     133    border-color: deepskyblue;
     134}
     135
     136.surveyButton:active {
     137    border-style: inset;
     138    border-color: orange;
     139}
     140
     141.question { 
     142    margin-top: 1em;
     143}
     144
     145.questionTable td{
     146    width: 8em;
     147}
     148
     149.questionTable th{
     150    text-align: left;
     151}
     152
     153label {
     154    font-size: small;
     155    font-weight: bold;
     156    color: gray;
     157}
  • Dev/trunk/submitsurvey.php

    r16 r17  
    4242}
    4343
     44var_dump($_POST);
     45
    4446?>
Note: See TracChangeset for help on using the changeset viewer.