JavaScript Button says [object HTMLButtonElement]












0














Here is my code:



var newRow = tableRef.insertRow(tableRef.rows.length);

var newCell0 = newRow.insertCell(0);
var newCell1 = newRow.insertCell(1);
var newCell2 = newRow.insertCell(2);
var newCell3 = newRow.insertCell(3);
var newCell4 = newRow.insertCell(4);
var newCell5 = newRow.insertCell(5);

newCell0.innerHTML = name.value;
newCell1.innerHTML = index.value;
newCell2.innerHTML = phonenum.value;
newCell3.innerHTML = grade.value;
newCell4.innerHTML = session.value;

var btn1 = document.createElement("BUTTON");
var btn2 = document.createElement("BUTTON");

var t1 = document.createTextNode("Confirm");
var t2 = document.createTextNode("Revert");

btn1.appendChild(t1);
btn2.appendChild(t2);
btn1.setAttribute('onclick', 'confirm(this);');
newCell5.appendChild(btn1);
btn2.setAttribute('onclick', 'revert(this);');
newCell5.appendChild(btn2);

function confirm(o) {
var tr = o.parentNode.parentNode;
tr.style.backgroundColor = "green";
}


What is the problem when I click on the button confirm it says [object HTMLButtonElement]?



Thanks in advance.










share|improve this question
























  • when i click on the button confirm it says ... what is saying that?
    – Bravo
    Nov 15 at 22:51










  • oh .. because confirm(this) is executing window.confirm most likely and the context of the function confirm means it's not overwriting window.confirm
    – Bravo
    Nov 15 at 22:53










  • On Chrome it says [object HTMLButtonElement] as an alert
    – Blaze
    Nov 15 at 22:53










  • it's not an alert, it's a confirm
    – Bravo
    Nov 15 at 22:54










  • try code that is a little more modern ... btn1.addEventListener('click', function(e) { confirm(this);});
    – Bravo
    Nov 15 at 22:55
















0














Here is my code:



var newRow = tableRef.insertRow(tableRef.rows.length);

var newCell0 = newRow.insertCell(0);
var newCell1 = newRow.insertCell(1);
var newCell2 = newRow.insertCell(2);
var newCell3 = newRow.insertCell(3);
var newCell4 = newRow.insertCell(4);
var newCell5 = newRow.insertCell(5);

newCell0.innerHTML = name.value;
newCell1.innerHTML = index.value;
newCell2.innerHTML = phonenum.value;
newCell3.innerHTML = grade.value;
newCell4.innerHTML = session.value;

var btn1 = document.createElement("BUTTON");
var btn2 = document.createElement("BUTTON");

var t1 = document.createTextNode("Confirm");
var t2 = document.createTextNode("Revert");

btn1.appendChild(t1);
btn2.appendChild(t2);
btn1.setAttribute('onclick', 'confirm(this);');
newCell5.appendChild(btn1);
btn2.setAttribute('onclick', 'revert(this);');
newCell5.appendChild(btn2);

function confirm(o) {
var tr = o.parentNode.parentNode;
tr.style.backgroundColor = "green";
}


What is the problem when I click on the button confirm it says [object HTMLButtonElement]?



Thanks in advance.










share|improve this question
























  • when i click on the button confirm it says ... what is saying that?
    – Bravo
    Nov 15 at 22:51










  • oh .. because confirm(this) is executing window.confirm most likely and the context of the function confirm means it's not overwriting window.confirm
    – Bravo
    Nov 15 at 22:53










  • On Chrome it says [object HTMLButtonElement] as an alert
    – Blaze
    Nov 15 at 22:53










  • it's not an alert, it's a confirm
    – Bravo
    Nov 15 at 22:54










  • try code that is a little more modern ... btn1.addEventListener('click', function(e) { confirm(this);});
    – Bravo
    Nov 15 at 22:55














0












0








0







Here is my code:



var newRow = tableRef.insertRow(tableRef.rows.length);

var newCell0 = newRow.insertCell(0);
var newCell1 = newRow.insertCell(1);
var newCell2 = newRow.insertCell(2);
var newCell3 = newRow.insertCell(3);
var newCell4 = newRow.insertCell(4);
var newCell5 = newRow.insertCell(5);

newCell0.innerHTML = name.value;
newCell1.innerHTML = index.value;
newCell2.innerHTML = phonenum.value;
newCell3.innerHTML = grade.value;
newCell4.innerHTML = session.value;

var btn1 = document.createElement("BUTTON");
var btn2 = document.createElement("BUTTON");

var t1 = document.createTextNode("Confirm");
var t2 = document.createTextNode("Revert");

btn1.appendChild(t1);
btn2.appendChild(t2);
btn1.setAttribute('onclick', 'confirm(this);');
newCell5.appendChild(btn1);
btn2.setAttribute('onclick', 'revert(this);');
newCell5.appendChild(btn2);

function confirm(o) {
var tr = o.parentNode.parentNode;
tr.style.backgroundColor = "green";
}


What is the problem when I click on the button confirm it says [object HTMLButtonElement]?



Thanks in advance.










share|improve this question















Here is my code:



var newRow = tableRef.insertRow(tableRef.rows.length);

var newCell0 = newRow.insertCell(0);
var newCell1 = newRow.insertCell(1);
var newCell2 = newRow.insertCell(2);
var newCell3 = newRow.insertCell(3);
var newCell4 = newRow.insertCell(4);
var newCell5 = newRow.insertCell(5);

newCell0.innerHTML = name.value;
newCell1.innerHTML = index.value;
newCell2.innerHTML = phonenum.value;
newCell3.innerHTML = grade.value;
newCell4.innerHTML = session.value;

var btn1 = document.createElement("BUTTON");
var btn2 = document.createElement("BUTTON");

var t1 = document.createTextNode("Confirm");
var t2 = document.createTextNode("Revert");

btn1.appendChild(t1);
btn2.appendChild(t2);
btn1.setAttribute('onclick', 'confirm(this);');
newCell5.appendChild(btn1);
btn2.setAttribute('onclick', 'revert(this);');
newCell5.appendChild(btn2);

function confirm(o) {
var tr = o.parentNode.parentNode;
tr.style.backgroundColor = "green";
}


What is the problem when I click on the button confirm it says [object HTMLButtonElement]?



Thanks in advance.







javascript html function object element






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 23:20









pushkin

3,939112651




3,939112651










asked Nov 15 at 22:45









Blaze

6




6












  • when i click on the button confirm it says ... what is saying that?
    – Bravo
    Nov 15 at 22:51










  • oh .. because confirm(this) is executing window.confirm most likely and the context of the function confirm means it's not overwriting window.confirm
    – Bravo
    Nov 15 at 22:53










  • On Chrome it says [object HTMLButtonElement] as an alert
    – Blaze
    Nov 15 at 22:53










  • it's not an alert, it's a confirm
    – Bravo
    Nov 15 at 22:54










  • try code that is a little more modern ... btn1.addEventListener('click', function(e) { confirm(this);});
    – Bravo
    Nov 15 at 22:55


















  • when i click on the button confirm it says ... what is saying that?
    – Bravo
    Nov 15 at 22:51










  • oh .. because confirm(this) is executing window.confirm most likely and the context of the function confirm means it's not overwriting window.confirm
    – Bravo
    Nov 15 at 22:53










  • On Chrome it says [object HTMLButtonElement] as an alert
    – Blaze
    Nov 15 at 22:53










  • it's not an alert, it's a confirm
    – Bravo
    Nov 15 at 22:54










  • try code that is a little more modern ... btn1.addEventListener('click', function(e) { confirm(this);});
    – Bravo
    Nov 15 at 22:55
















when i click on the button confirm it says ... what is saying that?
– Bravo
Nov 15 at 22:51




when i click on the button confirm it says ... what is saying that?
– Bravo
Nov 15 at 22:51












oh .. because confirm(this) is executing window.confirm most likely and the context of the function confirm means it's not overwriting window.confirm
– Bravo
Nov 15 at 22:53




oh .. because confirm(this) is executing window.confirm most likely and the context of the function confirm means it's not overwriting window.confirm
– Bravo
Nov 15 at 22:53












On Chrome it says [object HTMLButtonElement] as an alert
– Blaze
Nov 15 at 22:53




On Chrome it says [object HTMLButtonElement] as an alert
– Blaze
Nov 15 at 22:53












it's not an alert, it's a confirm
– Bravo
Nov 15 at 22:54




it's not an alert, it's a confirm
– Bravo
Nov 15 at 22:54












try code that is a little more modern ... btn1.addEventListener('click', function(e) { confirm(this);});
– Bravo
Nov 15 at 22:55




try code that is a little more modern ... btn1.addEventListener('click', function(e) { confirm(this);});
– Bravo
Nov 15 at 22:55












3 Answers
3






active

oldest

votes


















0














Confirm is a javascript function and your passing this. This in your scope is HTMLElement Object. Change your function and try again thanks.






share|improve this answer





























    -1














    I guess because window.confirm is a general function in JS to display a popup for a user to confirm or decline an action.



    You may try declaring your function more explicitly, like putting it into an object, or rename it into something else, like confirmSelection.






    share|improve this answer





















    • Thanks it worked i got rid of alert
      – Blaze
      Nov 15 at 23:01



















    -1














    If you're unintentionally seeing a print out somewhere (console.log, alert, etc.) that says [object HTMLButtonElement] then you're probably trying to print a string but instead handing the print statement an object, which results in printing out the object's type in brackets. Like @Bravo said, there isn't enough context and code. It would be helpful to know what your desired results are. If you're trying to print information about the button, like it's label, you could add .textContent after the name of your button to see the text within its html tag.






    share|improve this answer





















    • Thanks for the reply i understand now what that means and my intention was when i click on the button the row changes into green but i fixed it, it works. Thanks
      – Blaze
      Nov 15 at 23:03










    • No problem, glad it's solved!
      – Alexandra
      Nov 15 at 23:04











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328936%2fjavascript-button-says-object-htmlbuttonelement%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Confirm is a javascript function and your passing this. This in your scope is HTMLElement Object. Change your function and try again thanks.






    share|improve this answer


























      0














      Confirm is a javascript function and your passing this. This in your scope is HTMLElement Object. Change your function and try again thanks.






      share|improve this answer
























        0












        0








        0






        Confirm is a javascript function and your passing this. This in your scope is HTMLElement Object. Change your function and try again thanks.






        share|improve this answer












        Confirm is a javascript function and your passing this. This in your scope is HTMLElement Object. Change your function and try again thanks.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 at 23:44









        Edwin Dijas Chiwona

        34118




        34118

























            -1














            I guess because window.confirm is a general function in JS to display a popup for a user to confirm or decline an action.



            You may try declaring your function more explicitly, like putting it into an object, or rename it into something else, like confirmSelection.






            share|improve this answer





















            • Thanks it worked i got rid of alert
              – Blaze
              Nov 15 at 23:01
















            -1














            I guess because window.confirm is a general function in JS to display a popup for a user to confirm or decline an action.



            You may try declaring your function more explicitly, like putting it into an object, or rename it into something else, like confirmSelection.






            share|improve this answer





















            • Thanks it worked i got rid of alert
              – Blaze
              Nov 15 at 23:01














            -1












            -1








            -1






            I guess because window.confirm is a general function in JS to display a popup for a user to confirm or decline an action.



            You may try declaring your function more explicitly, like putting it into an object, or rename it into something else, like confirmSelection.






            share|improve this answer












            I guess because window.confirm is a general function in JS to display a popup for a user to confirm or decline an action.



            You may try declaring your function more explicitly, like putting it into an object, or rename it into something else, like confirmSelection.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 at 22:53









            Vladislav Korotnev

            1159




            1159












            • Thanks it worked i got rid of alert
              – Blaze
              Nov 15 at 23:01


















            • Thanks it worked i got rid of alert
              – Blaze
              Nov 15 at 23:01
















            Thanks it worked i got rid of alert
            – Blaze
            Nov 15 at 23:01




            Thanks it worked i got rid of alert
            – Blaze
            Nov 15 at 23:01











            -1














            If you're unintentionally seeing a print out somewhere (console.log, alert, etc.) that says [object HTMLButtonElement] then you're probably trying to print a string but instead handing the print statement an object, which results in printing out the object's type in brackets. Like @Bravo said, there isn't enough context and code. It would be helpful to know what your desired results are. If you're trying to print information about the button, like it's label, you could add .textContent after the name of your button to see the text within its html tag.






            share|improve this answer





















            • Thanks for the reply i understand now what that means and my intention was when i click on the button the row changes into green but i fixed it, it works. Thanks
              – Blaze
              Nov 15 at 23:03










            • No problem, glad it's solved!
              – Alexandra
              Nov 15 at 23:04
















            -1














            If you're unintentionally seeing a print out somewhere (console.log, alert, etc.) that says [object HTMLButtonElement] then you're probably trying to print a string but instead handing the print statement an object, which results in printing out the object's type in brackets. Like @Bravo said, there isn't enough context and code. It would be helpful to know what your desired results are. If you're trying to print information about the button, like it's label, you could add .textContent after the name of your button to see the text within its html tag.






            share|improve this answer





















            • Thanks for the reply i understand now what that means and my intention was when i click on the button the row changes into green but i fixed it, it works. Thanks
              – Blaze
              Nov 15 at 23:03










            • No problem, glad it's solved!
              – Alexandra
              Nov 15 at 23:04














            -1












            -1








            -1






            If you're unintentionally seeing a print out somewhere (console.log, alert, etc.) that says [object HTMLButtonElement] then you're probably trying to print a string but instead handing the print statement an object, which results in printing out the object's type in brackets. Like @Bravo said, there isn't enough context and code. It would be helpful to know what your desired results are. If you're trying to print information about the button, like it's label, you could add .textContent after the name of your button to see the text within its html tag.






            share|improve this answer












            If you're unintentionally seeing a print out somewhere (console.log, alert, etc.) that says [object HTMLButtonElement] then you're probably trying to print a string but instead handing the print statement an object, which results in printing out the object's type in brackets. Like @Bravo said, there isn't enough context and code. It would be helpful to know what your desired results are. If you're trying to print information about the button, like it's label, you could add .textContent after the name of your button to see the text within its html tag.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 at 23:00









            Alexandra

            596




            596












            • Thanks for the reply i understand now what that means and my intention was when i click on the button the row changes into green but i fixed it, it works. Thanks
              – Blaze
              Nov 15 at 23:03










            • No problem, glad it's solved!
              – Alexandra
              Nov 15 at 23:04


















            • Thanks for the reply i understand now what that means and my intention was when i click on the button the row changes into green but i fixed it, it works. Thanks
              – Blaze
              Nov 15 at 23:03










            • No problem, glad it's solved!
              – Alexandra
              Nov 15 at 23:04
















            Thanks for the reply i understand now what that means and my intention was when i click on the button the row changes into green but i fixed it, it works. Thanks
            – Blaze
            Nov 15 at 23:03




            Thanks for the reply i understand now what that means and my intention was when i click on the button the row changes into green but i fixed it, it works. Thanks
            – Blaze
            Nov 15 at 23:03












            No problem, glad it's solved!
            – Alexandra
            Nov 15 at 23:04




            No problem, glad it's solved!
            – Alexandra
            Nov 15 at 23:04


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328936%2fjavascript-button-says-object-htmlbuttonelement%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents