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

  • Home
  • SEARCH
  • 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 9023423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:45:28+00:00 2026-06-16T05:45:28+00:00

There are two numbers. User fills out answer & clicks enter or the next

  • 0

There are two numbers. User fills out answer & clicks enter or the “next” button (activate form)

I want the form to always “return false” as all next actions are loaded with javascript.
As long as the user keeps filling out the correct answer it works, but when you fill out the wrong answer, it first shows you the “hey you, what is this?” box, but twhen user tries to answer again, the entire page is realoaded :/

You can see it here:
http://skolresurser.se/matematik/simple/

HTML

<form id="theChallenge">
    <h1>
        <span class="first">2</span>
        <span style="position: relative; top: 0.24em; margin: 0 6px;">*</span>
        <span class="second">6</span>
        <span style="margin-left: 0.13em; font-size: 0.8em; position: relative; top: -0.13em; margin-right: -0.60em;">=</span>
    </h1>
    <div id="notReally" style="display: none;">
        <h2>Not reeaaaaally:</h2>
        <span id="actually"></span>
    </div>
    <input type="number" class="answerInput"><br>
    <button class="2btn btn-large btn-success checkAnswer" href="#">Next</button>
</form>

JS:

$(function() {
    function biggestNumber() {
        return Math.max.apply(this, arguments);
    }

    $("#theChallenge").submit(function() {
        first = $(".first").text();
        second = $(".second").text();
        correctAnswer = parseInt($(".first").text()) * parseInt($(".second").text()); //parseInt = omvandla text till siffra.. och slå ihop de två alternativen!  och detta är då vårt rätta svar        
        theAnswer = $(".answerInput").val() //Vad har användaren skrivit in för svar?
        alert('first' + first);

        //Check if answer is correct
        if (theAnswer == correctAnswer) {
            //Create new numbers
            var randomNum = 1 + Math.ceil(Math.random() * 12); /* Pick random number between 1 and 12 */
            $('.first').text(randomNum);
            var randomNum = 1 + Math.ceil(Math.random() * 12); /* Pick random number between 1 and 12 */
            $('.second').text(randomNum);
        } else {
            //Show the person doing the test that
            $("#notReally").slideDown('fast');
            $("h1").slideUp('medium');

            biggestNumber = biggestNumber(first, second); //en funktion som är inlagd längre upp!!
            if (biggestNumber == first) { //Om största numret = första numret, då är det, det andra numret vi vill stapla upp, annars är det ju första siffran vi vill stapla upp "största siffran antalet gånger".
                theOtherNumber = second;
            } else {
                theOtherNumber = first;
            }
            staplaUpp = theOtherNumber; //Börja med att lägga in den mindre siffran en gång först, och sedan för varje till  " +siffran "
            for (var i = 0; i < biggestNumber - 1; i++) { //För varje antal det finns av den mindre siffran, stapla upp den med plus emellan!
                staplaUpp = staplaUpp + '<span style="margin:0 0.2em;">+</span>' + theOtherNumber;
            }
            $("#actually").append(staplaUpp);

        }

        $(".answerInput").val('');
        alert('first' + first);
        return false;
    });
});
  • 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-16T05:45:29+00:00Added an answer on June 16, 2026 at 5:45 am

    Usually the form failing on the second submit is an indication that there was an error in your javascript event handler that prevented it from returning false. To debug these, it is useful to use the javascript console in your browser with the option to preserve the log information when navigating between pages. ( this option is called Preserve Log upon Navigation in the webkit debugger ). Using this technique, I found:

    Uncaught TypeError: number is not a function skolresurser.se:137
    (anonymous function)
    

    Looking at that section of code I can see the problem is here:

    biggestNumber = biggestNumber(first,second); //en funktion som är inlagd längre upp!!
    

    When you assign biggestNumber to the return value of itself, you overwrite the function biggestNumber with the number biggestNumber. Then, the second time you click the submit button, your code fails.

    Instead, you should be assigning that return value to a different variable:

         var bigNum = biggestNumber(first,second); //en funktion som är inlagd längre upp!!
           if(bigNum==first){ //Om största numret = första numret, då är det, det andra numret vi vill stapla upp, annars är det ju första siffran vi vill stapla upp "största siffran antalet gånger".
            theOtherNumber=second; 
           }else{
            theOtherNumber=first; 
           }
          staplaUpp = theOtherNumber;  //Börja med att lägga in den mindre siffran en gång först, och sedan för varje till  " +siffran "
    
           for(var i = 0; i < bigNum-1; i++) { //För varje antal det finns av den mindre siffran, stapla upp den med plus emellan!
                staplaUpp = staplaUpp + '<span style="margin:0 0.2em;">+</span>'+theOtherNumber;
            }
           $("#actually").append(staplaUpp); 
    

    Then your biggestNumber function is still a function the next time it’s called.

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

Sidebar

Related Questions

I have a form. The user will fill it out, and at the bottom
I am trying to take numbers from three EditText boxes that the user fills
I have a website that asks numerous users to fill out a form. There
There are two strings. String str1=Order Number Order Time Trade Number; String str2=Order Tm;
There are two classes, let's call them X and O. A number of elements
In this problem, I have three (identically-structured) lists. Two have all numbers and the
Say I have two files where there is one number per line File 1
Is there any easy way to calculate the number of lines changed between two
I have read a document that they say: In java there two types of
There are two intents on the receiver side which are called from the same

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.