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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    help with a javascript problem if possible please?

    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>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,086
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb Number of errors...

    Aside from a number of syntax errors in your original post (missing '}" and ';' characters and such),
    you have not defined the information for "answerC" or "answerD".

    If you use FF, turn on the error console and see the problems as they arise.

    Code:
    <html>
    <head>
    <script type="text/javascript"> <!-- archiac: LANGUAGE="JavaScript" -->
    // From: http://codingforums.com/showthread.php?t=198339
    
    <!-- hide this script tag's contents from old browsers  ***  STATEMENT NO LONGER NEEDED --->
    
    function jumpBox(list) {
       location.href = list.options[list.selectedIndex].value;
    }
    
    //Lee Quinn 2010  All Rights Reserved
    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 == 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 <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>
    </html>
    At least you have a display to continue to debug from.

    Good Luck!

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,015
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    This is double posted.
    creating a survey with HTML and Javascript -just cant seem to get it right :(


    And do please read the forum posting guidelines about silly thread titles.

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,086
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Arrow

    Quote Originally Posted by Philip M View Post
    This is double posted.
    creating a survey with HTML and Javascript -just cant seem to get it right :(


    And do please read the forum posting guidelines about silly thread titles.
    Thanks for saving me some additional wasted effort. I had not seen the other post.

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Firstly sorry for the double post and ive just found the "error console" which is very helpful. Thanks for all your help with this it is apprecaited.


    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
    •