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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:42:48+00:00 2026-06-02T22:42:48+00:00

I am stacked. My code can not prevent defaut action of submit. This was

  • 0

I am stacked. My code can not prevent defaut action of submit. This was working fine until I add this.doSomething();.

Why this happens? Do I have to use preventDefault?

working code: http://jsfiddle.net/WwW5R/

HTML:

<div id="container">
    <form action="" method="post" id="input">
            <input type="submit">
    </form>
</div>

JavaScript:

$(function() {
    var ReserveUI = function($el) {
        this.$form = {
            input: $el.find('#input')
        };
        this._eventify();
    };

    ReserveUI.prototype.doSomething = function() {
        return false;
    }

    ReserveUI.prototype._eventify = function() {
        this.$form.input.submit(function() {
            this.doSomething(); //if comment out this line, it works
            return false;
        });
    };
    var UI = new ReserveUI($("#container"));
});

thanks for reading:)

  • 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-02T22:42:51+00:00Added an answer on June 2, 2026 at 10:42 pm

    In your submit callback function, this no longer refers to your object, but to the element itself.

    It’s therefore causing an exception because the element has no doSomething property, and your return false is skipped.

    Instead, write this:

    ReserveUI.prototype._eventify = function() {
        var self = this;
        this.$form.input.submit(function(e) {
            e.preventDefault(); // cancels event even if subsequent lines fail
            self.doSomething();
        });
    };
    

    See http://jsfiddle.net/xgGGx/1/ for a working example showing that it’s just the scope issue causing the bug.

    This is what script debugging tools are for – the reported error should have made the fault reasonably obvious…

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

Sidebar

Related Questions

Stacked Vertical is working fine: http://jsfiddle.net/Q28Aj/1/ But if I change the bar to horizontal
I am coding program, and stacked. Please can give me a code which search
Currently I have a stacked bar chart like this ( jsfiddle demo ) I
I'm creating a stacked bar chart just like this one . Notice that the
Hello I am trying to create a stacked barplot using the following code: test
this is driving me absolutely nuts. I'm not the most experienced with CSS, so
i am stucked with this wysiwyg editor http://www.innovastudio.com/ . I am trying to add
I've stucked on this and can't find way out :/ I'm trying to do
<form action=userLogin.php method=post> <div id=login> <div id=submit class=h>Log In</div> &nbsp;Email <br> &nbsp;<input id=email name=email
Today at work I got stucked in a line of code I can't achieve

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.