Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9047161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:50:15+00:00 2026-06-16T11:50:15+00:00

I’m creating a survey-like page. I use three basic JavaScript functions, goNext(i) which hides

  • 0

I’m creating a survey-like page. I use three basic JavaScript functions, goNext(i) which hides a certain div tags and shows the next, goPrevious(i), which pretty much does the same but backwards, and answerExists(questionNumber) which checks if all radio buttons are checked. From the point I created answerExists(), goNext() and I suppose goPrevious() too, stopped responding. Maybe it’s something to do with the onsubmit() function, but I can’t figure it out. These are the JavaScript functions:

function goNext(i) {
  document.getElementById("div" + i).style.display = 'none';
  document.getElementById("div" + (i + 1)).style.display = 'block';
}

function goPrevious(i) {
  document.getElementById("div" + i).style.display = 'none';
  document.getElementById("div" + (i - 1)).style.display = 'block';
}

function checkAnswers(questions) {
  var answers = new Array(questions);
  for(var i = 1; i <= questions; i++){
    answers[i-1] = false;
    var radio = document.getElementsByClassName('Radio' + i);
    for (var j=0; j < radio.length; j++) {
      if(radio[j].checked == true)
         alert(radio[j].value)answers[i-1] = true;
    }
    for (var i = 0; i < questions; i++){
      if(answers[i] == false){
        alert("Please answer all questions.");
        return false;
      }   
    }
    return true;
}

And this is the HTML form:

<form id="content" action="getresults.jsp" method="post" onsubmit="return checkAnswers(2);">
    <div id="div1" style="display: block;">
        <strong>1. Question 1</strong><br><br>&nbsp;&nbsp;
        <input id="radio1" class="radio1" name="radio1" onclick="if (this.__chk) this.checked = false" onmousedown="this.__chk = this.checked" type="radio" value="Answer1" /> 
        Answer1<br><br><br><br>
        <div class="auto-style1">
            <input name="next" onclick="goNext(1);" type="button" value="Next" />
        </div>
    </div>
    <div id="div2" style="display: none;">
        <strong>2. Question 2</strong><br><br>&nbsp;&nbsp;
        <input id="radio2" class="radio2" name="radio2" onclick="if (this.__chk) this.checked = false" onmousedown="this.__chk = this.checked" type="radio" value="Answer 2" /> 
        Answer 2<br><br>&nbsp;&nbsp;
        <input id="radio2" class="radio2" name="radio2" onclick="if (this.__chk) this.checked = false" onmousedown="this.__chk = this.checked" type="radio" value="dfgdgfdgf" /> 
        dgfgddgf<br><br><br><br>
        <div class="auto-style1">
            <input name="previous" onclick="goPrevious(2);" type="button" value="Previous" />&nbsp;
            <input name="submit" type="submit" value="Submit" />
        </div>
    </div>
</form>

It is actually all created dynamically, but still, it worked before I added the checkAnswers() function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:50:17+00:00Added an answer on June 16, 2026 at 11:50 am

    The problem is that you have syntax errors in your checkAnswers function, and the interpreter discards any scripts that contain syntax errors, so all your other functions get discarded, too.

    These are the two syntax errors:

    • alert(radio[j].value)answers[i-1] = true; is not a valid statement. (I’m guessing that you intended to delete the alert(radio[j].value) part, but highlighted the wrong thing?)
    • You have more left-curly-braces { than right-curly-braces }.

    Once you fix both of these issues, the script should at least run (though you may still have some debugging to do).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am trying to render a haml file in a javascript response like so:
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am confused How to use looping for Json response Array in another Array.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.