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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question javascript form help needed

    I will be completely up front about this, its school work. At the end of a basic html class I missed several classes for family reasons and missed just about everything on Javascript. The book we used basically didnt cover anything over it, was all in class learning I missed. Anyone who could help would be so helpful.

    One function is partial, one is blank, thats what is supposed to be added/corrected to the following code

    Code:
    <html>
    <head>
    
    <script language="javascript" type="text/javascript">
    
    function processScore()
    {
    var score = 0;
    if ( ...checked)
    {score = score + 1;}
    if (...checked)
    {score = score + 1;}
    document.answerForm.score.value = score;
    // Display the correct answers
    document.answerForm.answer1.value = " "; // put the correct value here
    document.answerForm.answer2.value = " "; // put the correct value here
    } //End of function processScore
    
    function clearForm()
    {
    // using the a javascript method clear all forms
    }
    </script>
    
    </head>
    
    <body style="font-family:tahoma; font-size:15px; line-height:200%; width:80%; margin-left:auto; margin-right:auto;">
    <hr color="red" width="60%" size="5">
    <form name="question1" id="question1">
    1. Which of the following is the document considered to be?<br/>
    <input type = "radio" name="choiceRB">
    a. object<br />
    <input type = "radio" name="choiceRB">
    b. property<br />
    <input type = "radio" name="choiceRB">
    c. method<br />
    </form>
    <hr color="green" width="60%" size="5">
    <form name="question2" id="question2">
    2. Which method of the window can be used to display a message to the user?<br/>
    <input type = "radio" name="choiceRB">
    a. display()<br />
    <input type = "radio" name="choiceRB">
    b. message()<br />
    <input type = "radio" name="choiceRB">
    c. alert()<br />
    </form>
    <hr color="red" width="60%" size="5">
    <input type="button" value="Grade the Quiz" onclick=?> <input type="button" value="Start Over" onclick=?>
    <form name="answerForm" id="answerForm">
    <p><strong>Correct Answers:</strong><br/></p>
    Question 1: <input type="text" name="answer1" size="1"><br />
    Question 2: <input type="text" name="answer2" size="1"><br />
    <p>You scored <input type="text" name="score" size = "1"> out of 2</p>
    
    </form>
    <br />
    </body>
    </html>

    thnx in advance to anyone who can help

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,141
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Here you are:-

    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    
    function processScore() {
    var score = 0;
    if (document.question1.choiceRB1[0].checked) {score = score + 1;}
    if (document.question2.choiceRB2[2].checked) {score = score + 1;}
    document.answerForm.score.value = score;
    document.answerForm.answer1.value = "Object"; 
    document.answerForm.answer2.value = "Alert";
    } 
    
    function clearForm(){
    document.question1.reset();
    document.question2.reset();
    document.answerForm.reset();
    return false;
    }
    </script>
    
    </head>
    
    <body style="font-family:tahoma; font-size:15px; line-height:200%; width:80%; margin-left:auto; margin-right:auto;">
    <hr color="red" width="60%" size="5">
    <form name="question1" id="question1">
    1. Which of the following is the document considered to be?<br/>
    <input type = "radio" name="choiceRB1">
    a. object<br />
    <input type = "radio" name="choiceRB1">
    b. property<br />
    <input type = "radio" name="choiceRB1">
    c. method<br />
    </form>
    <hr color="green" width="60%" size="5">
    <form name="question2" id="question2">
    2. Which method of the window can be used to display a message to the user?<br/>
    <input type = "radio" name="choiceRB2">
    a. display()<br />
    <input type = "radio" name="choiceRB2">
    b. message()<br />
    <input type = "radio" name="choiceRB2">
    c. alert()<br />
    </form>
    <hr color="red" width="60%" size="5">
    <input type="button" value="Grade the Quiz" onclick="processScore()"> 
    <input type="button" value="Start Over" onclick="clearForm()">
    <form name="answerForm" id="answerForm">
    <p><strong>Correct Answers:</strong><br/></p>
    Question 1: <input type="text" name="answer1" size="12"><br />
    Question 2: <input type="text" name="answer2" size="12"><br />
    <p>You scored <input type="text" name="score" size = "1"> out of 2</p>
    
    </form>
    <br />
    </body>
    </html>
    <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.

    BTW, the time to say "thanks" is afterwards, not beforehand which gives the - doubtless unintended - impression that you take other people's voluntary unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.

    "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." Brian W. Kernighan


  •  

    Posting Permissions

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