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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:04:21+00:00 2026-06-14T22:04:21+00:00

here is my code var addproduct = { init:function(){ var footer = $(<div class=’footer’></div>);

  • 0

here is my code

var addproduct = {
    init:function(){
        var footer = $("<div class='footer'></div>");
        var confirmButton = $("<button class='dbtn'>confirm</button>").on('click',this.confirm);
        var cancelButton = $("<button class='dbtn'>cancel</button>").on('click',this.cancel);
        d.append(footer.append(confirmButton,cancelButton));

        $('body').append(d)
    },

    getData:function(){
        var data={};
        d.find('#basic_info :input').each(function(){
            data[$(this).attr('name')] = $(this).val()
        });
        console.log(data);
        return data;
    },

    confirm:function(e){

        console.log(e.data);
    },

    cancel:function(){
        alert(2);
    }

}

when i click the confirm button i want to submit the form in ‘d’,so i want to use ‘getData’ function to get all the form data,

here is what i did

var confirmButton = $("<button class='dbtn'>confirm</button>").on('click',this.getData,this.confirm);

//output: function()

so i guess the data pass to the handler can not be a function right???

and then i change the confirm function like this

confirm:function(){

     var data = this.getData()
     console.log(data);
    },

 this will not work too , because the 'this' keyword is not the addproduct object,but the confirm button '<button>confirm</button>';

so how can i pass the getData function’s return data to confirm function?????

and why the ‘this’ isn’t the addproduct object ???

  • 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-14T22:04:22+00:00Added an answer on June 14, 2026 at 10:04 pm

    Try

    var confirmButton = $("<button class='dbtn'>confirm</button>")
                         .on('click',this.getData(),this.confirm);
    

    getData returns the data object you want to pass to the event handler so you have to actually call the function. Then you should be able to see the data here

    confirm:function(e){
    
        console.log(e.data);
    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is some code: var class = function(elem,div){ this.elem= elem; this.div = div; this.init
Here is my code: var showNo = 1; window.setInterval(function() { console.log(showNo); if(showNo === 1)
I have this code here: var Person = (function() { var name; var PersonConstructor
Here is my chunk of code: var update_shipping_methods = function(methods) { $(methods).each( function(i) {
I have the following code: var myModule = (function($) { // Insert code here
Here is my code: var A = (function(){ use strict; function FetchJSON(){ return someValue;
Here is my code: var $container = jQuery('#hentry-wrapper'); $container.imagesLoaded( function(){ $container.masonry({ itemSelector : '.hentry',
Here is my code: var randomNumber = function(from,to,dec) { var num = Math.random()*(to-from+1)+from; var
I check like this: enter code here var point = new g.LatLng(parseFloat(lat),parseFloat(lng)); var bounds
I've been here and accordingly found out that this piece of code here var

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.