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 8363243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:07:47+00:00 2026-06-09T12:07:47+00:00

I’m making a web application for a class which contains a jsp file that

  • 0

I’m making a web application for a class which contains a jsp file that uses jquery. I want the app to trigger an alert right before submitting. This works some of the time in my real program, and other times the alert is never triggered. I can’t seem to peg down an instance where it always works or never works. My error console is silent on the matter, unless I add Firebug breakpoints. Then it gives me

Error: attempt to run compile-and-go script on a cleared scope
Source File: http://code.jquery.com/jquery-1.7.2.min.js
Line: 2

But I have no idea what that means. As far as Firebug goes, I can’t understand why the evaulation stops before the alert message.

I tried to make an sscce documenting the problem, but I guess it was too different from my real program, because submit never worked. I’ll show some code from my real program. (Sorry about the lack of SSCCE.)

$(document).ready(function() {
    $("#questionDisplay").submit(function() {
        var correctAnswer = $(".correctAnswer").attr("value");
        var answer = "";

        if ($(".multipleChoice").length > 0) {
            answers = $("input:checked");
            for (var obj in answers) {
                answer += obj.attr("value") + "#";
            }
        } else if ($(".fillBlank").length > 0) {
            for (var answerNo = 1; $(".answer" + answerNo).length > 0; ++answerNo) {
                answer += $(".answer" + answerNo).attr("value") + "#";
            }
        } else {
            answer = $(".answer1").attr("value");
        }

        if (answer == correctAnswer) {
            alert("Yes! Correct!");
        } else {
            alert("Sorry, incorrect.");
        }
    });
});

The jsp is a huge mess (we have to use scriplets 🙁 ), but if you’d like to see it just lemme know.

How do I get my submit handler to work every time?

  • 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-09T12:07:48+00:00Added an answer on June 9, 2026 at 12:07 pm

    In your example, answers is a jQuery collection of elements. Looping through it using for(var obj in answers) { } is actually looping through the properties of answers, not the elements themselves. Therefore, calling .attr() on a property is not going to work.

    In general, if I see my debugger state that jQuery has an error, it’s 99.9% of the time me calling a jQuery method on a non-jquery selected object. In this case, I saw the error in Chrome’s JavaScript console, and sometimes results may vary with different consoles.

    A good practice is to prefix variables that store jQuery elements with $ to indicate that they are jQuery objects. For instance, $answers makes it easier to keep track of what it contains.

    Use:

    answers.each(function() {
         answer += $(this).attr("value") + "#";
    });
    

    Instead of this:

    for (var obj in answers) {
        answer += obj.attr("value") + "#";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.