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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:31:30+00:00 2026-05-23T00:31:30+00:00

My page shows a window with a confirmation. If I choose Yes, the method

  • 0

My page shows a window with a confirmation.

If I choose Yes, the method Method1 runs but an error is generated saying that the object [Object DOMWindow] has no method ‘Method2’.

How can I solve this?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Testes Javascript O.O.</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" /> 
<link type="text/css" href="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.css" rel="stylesheet" /> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script> 
<script type="text/javascript" src="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.js"></script>
<script type="text/javascript">
var vssMkt = {};

var MsgBoxSimNao = function (parMensagem, parFuncaoSim, parFuncaoNao) {
    /// <sumary>Abre uma caixa de dialogo com uma mensagem e um botao de Sim e outro de Nao.</sumary>
    /// <param name="parMensagem" type="String">Mensagem a ser exibida.</param>
    /// <param name="parFuncaoSim" type="Function">Funcao a ser executada quando clicar no Sim.</param>
    /// <param name="parFuncaoNao" type="Function">Funcao a ser executada quando clicar no Nao.</param>
    $(this).simpledialog({
        'mode': 'bool',
        'prompt': parMensagem,
        'useDialogForceFalse': true,
        'buttons': {
            'Yes': {
                click: parFuncaoSim // Callback func if I press Yes
            },
            'No': {
                click: parFuncaoNao // Callback func if I press No
            }
        }
    })
}

var Obj1 = function () {
    this.Method1 = function () {
        MsgBoxSimNao("Show message?",
            this.Msg1,
            this.Msg2
        );
    }

    this.Method2 = function () {
        alert('Method 2');
    }

    this.Msg1 = function (parMsg) {
        alert('Yes');
        this.Method2();
    }

    this.Msg2 = function () {
        alert('No');
    }
}

function onLoad() {
    vssMkt.test = new Obj1();
    $("#link").click(function () {
        vssMkt.test.Method1();
    });
}

</script>
</head>

<body onLoad="onLoad();">
<div data-role="page">
  <div data-role="header">
    <h1>Javascript error</h1>
  </div>
  <!-- /header -->
  <div data-role="content">
  <a id="link" href="#" data-role="button">Start test</a>
  </div>
  <!-- /content --> 
</div>
<!-- /page -->
</body>
</html>
  • 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-05-23T00:31:31+00:00Added an answer on May 23, 2026 at 12:31 am

    Edited

    Sorry, first answer was not correct.

    Your issue is in the constructor. Since you are passing methods to other functions for them to call, they need to keep a reference to the instance in a closure.

    > var Obj1 = function () {
    >     this.Method1 = function () {
    >         MsgBoxSimNao("Show message?",
    >             this.Msg1,
    >             this.Msg2
    >         );
    >     }
    

    To keep a reference to the instance, change it to:

    var Obj1 = function () {
    
        // Reference to the instance
        var obj = this;
    
        this.Method1 = function () {
            MsgBoxSimNao("Show message?",
                this.Msg1,
                this.Msg2
            );
        }
    

    In the call you have:

    >     this.Method1 = function () {
    >         MsgBoxSimNao("Show message?",
    >             this.Msg1,
    >             this.Msg2
    >         );
    >     }
    

    so this.Msg1 and this.Msg2 will pass references to those functions when Method1 is called. When they are called from MsgBoxSimNao, they are called without any qualification so when Msg1 is called:

    >     this.Msg1 = function (parMsg) {
    >         alert('Yes');
    >         this.Method2();
    >     }
    

    within the function this is set to the global object. Change the method to keep a reference to the instance:

    this.Msg1 = function (parMsg) {
        alert('Yes');
        obj.Method2();
    }
    

    obj references the instance and its Method2 will be called. There are other ways to do it, but this is the simplest (to me anyway).

    Untested, but should work.

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

Sidebar

Related Questions

In this tutorial I am reading , Dave Ward creates a page that shows
This little web page runs fine on my desktop but when selecting the area
I have a fancybox modal window that loads a page of content (a form).
How can I show a web page in a transparent window and have the
I basically have a page which shows a processing screen which has been flushed
In a JSP page(index.jsp): ${requestContext.requestURL} is the URL just shows the expression itself. It
When my ASP.NET application crashes (when it shows the default exception page), I'd like
I want to write a page that will show all the records from a
I have a struts2 application with a single page that may show one of
I have a page that uses $(id).show(highlight, {}, 2000); to highlight an element when

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.