Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    creating a survey with HTML and Javascript -just cant seem to get it right :(

    Hi im wondering if someone could be of some help please, im a newbie to javascript and after some help and advice if possible please. Ive used a template from the web which was a quiz template. Im just trying to get my javascript script to work. I want it to populate my html question/advice box so people can input what there answer to the question and it will give them advice. It's for a data classification advice for a work project. I just dont know where im going wrong or what im missing out - ive read loads of help sections on the web and still cant get the javascript to populate my html boxes. Any help or advice would be really appreciated.

    Thanks

    Lee

    Heres my html code which seems to work ok... the box etc is displayed just doesnt have any content.
    -----------------------------------------------------------------------
    Code:
     <form method="POST">
      <div align="center"><center><table BORDER="1">
        <tr>
          <td COLSPAN="2" BGCOLOR="#4C0000"><div align="center"><center><p><font SIZE="+3"
          COLOR="#FFFFFF">Data Classification </font></td>
        </tr>
        <tr>
          <td COLSPAN="2" BGCOLOR="#4C0000"><div align="center"><center><p><font SIZE="-1"
          COLOR="#FFFFFF">2010 <a HREF="Data Governance</font> </p>
          </center></div><div align="center"><center><p><font COLOR="#FFFFFF">Click on &quot;Next
          Question&quot; to start advice. Be sure to use small letters (no caps) when entering your
          letter choice.</font> </td>
        </tr>
        <tr>
          <td><b>Question&nbsp;#:</b></td>
          <td ALIGN="LEFT"><input TYPE="TEXT" NAME="questNo" SIZE="4"></td>
        </tr>
        <tr>
          <td><b>Question:</b></td>
          <td><div align="center"><center><p><textarea COLS="70" ROWS="2" name="question"
          wrap="virtual"></textarea></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>a)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceA" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>b)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceB" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>c)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceC" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>d)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceD" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>Your choice:</b></td>
          <td><input TYPE="TEXT" NAME="yourChoice" SIZE="4"></td>
        </tr>
        <tr>
          <td COLSPAN="2"><div align="center"><center><p><input TYPE="button"
          VALUE="Check Current Advice" onClick="checkAnswer(this.form)"><input TYPE="button"
          VALUE="Next Question" onClick="nextQuestion(this.form)"> <input TYPE="reset"
          VALUE="Start Over" onClick="clearForm(this.form)"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>Results:</b></td>
          <td><div align="center"><center><p><textarea COLS="70" ROWS="3" name="Advice"
          wrap="virtual"></textarea></td>
        </tr>
        <tr>
    </form>
    --------------------------------------------------------------------------
    Now heres my javascript which i just cant seem to get to work or integrate with the html question/advice box. There will be some text in there that was originally part of the template that i was going to remove at a later stage once id got a better underatnding of where i was going wrong.


    Code:
     <html>
    <head>
    <script LANGUAGE="JavaScript">
    
    
    <!-- hide this script tag's contents from old browsers --->
    
    function jumpBox(list) {
       location.href = list.options[list.selectedIndex].value
       }
    
    //Lee Quinn 2010  All Rights Reserved
    
    
    function init() 
                  {
    
                                 
    
                  questions = new Array()
                  questions[1] = "Is the information you are collecting or creating any of the following?"
                  questions[2] = "Is the information you are collecting or creating any of the following?"
                  questions[3] = "Is the information you are collecting or creating any of the following?"
                  questions[4] = "Is the information you are collecting or creating any of the following?"
                  
    
                  answerA = new Array()
                  answerA[1] = "Marketing brochures, Customer disclosure statements,Published annual reports, Interviews with news media, Press releases"
                  answerA[2] = "Employee Handbook,Telephone Directory,Organization Charts,Policies and Standards,Training Manuals"
                  answerA[3] = "Customer records, Correspondence containing customer information, Credit card listings,Personnel records/Employee performance reviews,Unit business plans,Proprietary/custom software,Budget information,Internal audit reports,Business reports on strategy, exposures etc"
                  answerA[4] = "Strategic Plans,Encryption keys,Details of mergers or acquisitions,Financial results prior to publication,Online access codes such as passwords or pin"
                  
    
                  answerB = new Array()
                  answerB[1] = "None of the above"
                  answerB[2] = "None of the above"
                  answerB[3] = "None of the above"
                  answerB[4] = "None of the above"
                  
                  
                  rightAns = new Array
                  rightAns[1] = "A"
                  rightAns[2] = "b"
                  rightAns[3] = "c"
                  rightAns[4] = "d"
                  
                  reference = new Array()
                  reference[1] = "You have indicated yes to question 1, therefore the information you are collecting/creating will be classified as PUBLIC information. It is information that can be disclosed to anyone without violating an individual?s right to privacy. Knowledge of this information does not expose CFS to financial loss, embarrassment, or jeopardize the security of assets."
                  reference[2] = "You have indicated yes to question 2, therefore the information you are collecting/creating will be classified as INTERNAL USE information. It is information that, due to technical or business sensitivity, is limited to employees and contractors who work on-site. It is intended for use only within CFS. Unauthorized disclosure, compromise, or destruction would not have a significant impact on CFS or its employees."
                  reference[3] = "You have indicated yes to question 3, therefore the information you are collecting/creating will be classified as CONFIDENTIAL information. It is information that CFS and its employees have a legal, regulatory, or social obligation to protect. It is intended for use solely within defined groups in CFS. Unauthorized disclosure, compromise, or destruction would adversely impact CFS its customers or its employees. 
    Unless otherwise stated all data should be treated as CONFIDENTIAL.Sensitive data = Confidential or Highly Confidential data."
                  reference[4] = "You have indicated yes to question 4, therefore the information you are collecting/creating will be classified as HIGHLY CONFIDENTIAL information, It is the highest level of classification and is information whose unauthorized disclosure, compromise, or destruction could result in severe damage, provide significant advantage to a competitor, or incur serious financial impact to CFS or its employees. It is intended for restricted use by a very small number of people (possibly 0 or 1) with an explicit, predetermined need to know."
        
    
                  } 
    
    function nextQuestion(form)
    
    //set the total number of questions equal to quizend
    
    {   var quizEnd = eval(4 * 1);
    
        if(form.questNo.value =5= quizEnd) {
    
           form.question.value = "1";
    
           form.choiceA.value = "Marketing brochures, Customer disclosure statements,Published annual reports, Interviews with news media, Press releases";
    
           form.choiceB.value = "None of the above";
    
           form.choiceC.value = "Unsure";
    
           form.yourChoice.value = "a,b,c,d";
    
           form.results.value = "End of Advice.  Your final results are listed below."; } else {
    
        if(form.questNo.value == "") {form.questNo.value = 1} else {
        
           form.questNo.value = eval(form.questNo.value) + 1;
    
        }
        form.question.value = questions[form.questNo.value];
    
        form.choiceA.value = answerA[form.questNo.value];
    
        form.choiceB.value = answerB[form.questNo.value];
    
        form.choiceC.value = answerC[form.questNo.value];
    
        form.choiceD.value = answerD[form.questNo.value];
    
        form.yourChoice.value = "";
    
        form.results.value = "";
    
        if(form.myScore.value == "") {form.myScore.value = 0; } else {
                                                      form.myScore.value = form.myScore.value; }
    
       }
    
    }
    
       function checkcurrentadvice(form) {
          
          var myScore = 0;
          var curve = 0;
    
          if(form.results.value != "") {form.results.value = "Sorry, no guessing allowed.  In order to retry this question you will have to start the quiz over.  Click on ''Next Question'' to continue."; }
    
          else if(form.yourChoice.value == rightAns[form.questNo.value]) {
          form.myScore.value = eval(form.myScore.value) + eval(1);
          form.results.value = "Conratulations!  You are correct. That brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ".  Click on ''Next Question'' to continue."; } else {
          
          form.results.value = "Sorry, you are incorrect. Please refer to " + reference[form.questNo.value] + " before retaking the quiz.  This brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ".  Click on ''Next Question'' to continue." }
    
    
    function clearForm(form)
    
    {
    
        
        form.questNo.value = "";
        form.question.value = "";
        form.choiceA.value = "";
        form.choiceB.value = "";
        form.choiceC.value = "";
        form.choiceD.value = "";
        form.yourChoice.value = "";
        form.results.value = "";
        form.myScore.value = "";
        form.percent.value = "";
        form.grade.value = "";
        
    
    }
    
    </script>
    </head>
    </html>
    Last edited by leeq61; 06-17-2010 at 01:46 PM. Reason: never used the [CODE] entry properly

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from Java forum to Javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,495
    Thanks
    3
    Thanked 500 Times in 487 Posts
    I have corrected a number of HTML and Javascript errors

    see if you can move forward

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    
    
    
    function jumpBox(list) {
       location.href = list.options[list.selectedIndex].value
       }
    
    //Lee Quinn 2010  All Rights Reserved
    
    
    
    
                 var questions = [];
                  questions[1] = "Is the information you are collecting or creating any of the following?"
                  questions[2] = "Is the information you are collecting or creating any of the following?"
                  questions[3] = "Is the information you are collecting or creating any of the following?"
                  questions[4] = "Is the information you are collecting or creating any of the following?"
    
    
                  var answerA = [];
                  answerA[1] = "Marketing brochures, Customer disclosure statements,Published annual reports, Interviews with news media, Press releases"
                  answerA[2] = "Employee Handbook,Telephone Directory,Organization Charts,Policies and Standards,Training Manuals"
                  answerA[3] = "Customer records, Correspondence containing customer information, Credit card listings,Personnel records/Employee performance reviews,Unit business plans,Proprietary/custom software,Budget information,Internal audit reports,Business reports on strategy, exposures etc"
                  answerA[4] = "Strategic Plans,Encryption keys,Details of mergers or acquisitions,Financial results prior to publication,Online access codes such as passwords or pin"
    
    
                  var answerB = [];
                  answerB[1] = "None of the above"
                  answerB[2] = "None of the above"
                  answerB[3] = "None of the above"
                  answerB[4] = "None of the above"
    
                  var answerC = [];
                  answerC[1] = "None of the above"
                  answerC[2] = "None of the above"
                  answerC[3] = "None of the above"
                  answerC[4] = "None of the above"
    
                  var answerD = [];
                  answerD[1] = "None of the above"
                  answerD[2] = "None of the above"
                  answerD[3] = "None of the above"
                  answerD[4] = "None of the above"
    
    
                  var rightAns = [];
                  rightAns[1] = "A"
                  rightAns[2] = "b"
                  rightAns[3] = "c"
                  rightAns[4] = "d"
    
                  var reference = [];
                  reference[1] = "You have indicated yes to question 1, therefore the information you are collecting/creating will be classified as PUBLIC information. It is information that can be disclosed to anyone without violating an individual?s right to privacy. Knowledge of this information does not expose CFS to financial loss, embarrassment, or jeopardize the security of assets."
                  reference[2] = "You have indicated yes to question 2, therefore the information you are collecting/creating will be classified as INTERNAL USE information. It is information that, due to technical or business sensitivity, is limited to employees and contractors who work on-site. It is intended for use only within CFS. Unauthorized disclosure, compromise, or destruction would not have a significant impact on CFS or its employees."
                  reference[3] = "You have indicated yes to question 3, therefore the information you are collecting/creating will be classified as CONFIDENTIAL information. It is information that CFS and its employees have a legal, regulatory, or social obligation to protect. It is intended for use solely within defined groups in CFS. Unauthorized disclosure, compromise, or destruction would adversely impact CFS its customers or its employees. Unless otherwise stated all data should be treated as CONFIDENTIAL.Sensitive data = Confidential or Highly Confidential data."
                  reference[4] = "You have indicated yes to question 4, therefore the information you are collecting/creating will be classified as HIGHLY CONFIDENTIAL information, It is the highest level of classification and is information whose unauthorized disclosure, compromise, or destruction could result in severe damage, provide significant advantage to a competitor, or incur serious financial impact to CFS or its employees. It is intended for restricted use by a very small number of people (possibly 0 or 1) with an explicit, predetermined need to know."
    
    
    
    function nextQuestion(form){
    
    //set the total number of questions equal to quizend
    
       var quizEnd = 4 * 1;
    
        if(form.questNo.value==5==quizEnd) {
    
           form.question.value = "1";
    
           form.choiceA.value = "Marketing brochures, Customer disclosure statements,Published annual reports, Interviews with news media, Press releases";
    
           form.choiceB.value = "None of the above";
    
           form.choiceC.value = "Unsure";
    
           form.yourChoice.value = "a,b,c,d";
    
           form.results.value = "End of Advice.  Your final results are listed below.";
        }
    
     else {
      if(form.questNo.value == "") {
      form.questNo.value = 1;
     }
        else {
    
           form.questNo.value = eval(form.questNo.value) + 1;
    
        }
        form.question.value = questions[form.questNo.value];
    
        form.choiceA.value = answerA[form.questNo.value];
    
        form.choiceB.value = answerB[form.questNo.value];
    
        form.choiceC.value = answerC[form.questNo.value];
    
        form.choiceD.value = answerD[form.questNo.value];
    
        form.yourChoice.value = "";
    
        form.results.value = "";
    
        if(form.myScore.value == "") {
         form.myScore.value = 0;
        }
        else {
         form.myScore.value = form.myScore.value;
        }
    
       }
    
    }
    
       function checkcurrentadvice(form) {
    
          var myScore = 0;
          var curve = 0;
    
          if(form.results.value != "") {
           form.results.value = "Sorry, no guessing allowed.  In order to retry this question you will have to start the quiz over.  Click on ''Next Question'' to continue.";
          }
    
          else if(form.yourChoice.value == rightAns[form.questNo.value]) {
           form.myScore.value = eval(form.myScore.value) + eval(1);
           form.results.value = "Conratulations!  You are correct. That brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ".  Click on ''Next Question'' to continue.";
          }
          else {
           form.results.value = "Sorry, you are incorrect. Please refer to " + reference[form.questNo.value] + " before retaking the quiz.  This brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ".  Click on ''Next Question'' to continue.";
          }
    }
    
    function clearForm(form){
    
    
        form.questNo.value = "";
        form.question.value = "";
        form.choiceA.value = "";
        form.choiceB.value = "";
        form.choiceC.value = "";
        form.choiceD.value = "";
        form.yourChoice.value = "";
        form.results.value = "";
        form.myScore.value = "";
        form.percent.value = "";
        form.grade.value = "";
    
    
    }
    
    </script>
    </head>
    
    <body>
    <form method="POST">
      <div align="center"><center><table BORDER="1">
        <tr>
          <td COLSPAN="2" BGCOLOR="#4C0000"><div align="center"><center><p><font SIZE="+3"
          COLOR="#FFFFFF">Data Classification </font></td>
        </tr>
        <tr>
          <td COLSPAN="2" BGCOLOR="#4C0000"><div align="center"><center><p><font SIZE="-1"
          COLOR="#FFFFFF">2010 Data Governance</font> </p>
          </center></div><div align="center"><center><p><font COLOR="#FFFFFF">Click on &quot;Next
          Question&quot; to start advice. Be sure to use small letters (no caps) when entering your
          letter choice.</font> </td>
        </tr>
        <tr>
          <td><b>Question&nbsp;#:</b></td>
          <td ALIGN="LEFT"><input TYPE="TEXT" NAME="questNo" SIZE="4"></td>
        </tr>
        <tr>
          <td><b>Question:</b></td>
          <td><div align="center"><center><p><textarea COLS="70" ROWS="2" name="question"
          wrap="virtual"></textarea></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>a)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceA" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>b)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceB" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>c)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceC" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>d)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceD" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>Your choice:</b></td>
          <td><input TYPE="TEXT" NAME="yourChoice" SIZE="4"></td>
        </tr>
        <tr>
          <td COLSPAN="2"><div align="center"><center><p><input TYPE="button"
          VALUE="Check Current Advice" onClick="checkAnswer(this.form)"><input TYPE="button"
          VALUE="Next Question" onClick="nextQuestion(this.form)"> <input TYPE="reset"
          VALUE="Start Over" onClick="clearForm(this.form)"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>Results:</b></td>
          <td><div align="center"><center><p><textarea COLS="70" ROWS="3" name="Advice"
          wrap="virtual"></textarea></td>
        </tr>
        <tr>
    </form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • Users who have thanked vwphillips for this post:

    leeq61 (06-18-2010)

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    firstly apologies for placing this in the wrong area of the forum and Thanks Vic thats a great help. Ive compared my original script with the one youve amaneded and can see where ive gone wrong. I should now be able to carry on. So once again thanks for your help (I thought javascript was going to be a breeze as HTML i can understand and do basic features etc, Javascript is like trying to learn chinese lol)

    Thanks

    Lee


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •