简体   繁体   中英

JavaScript called from Div onclick running button.click call

I have a Div onclick function that calls the JavaScript function below

function MonthViewDay(sDate){
        var txtHidden = document.getElementById('<%=txtHidden.ClientID %>');
        var btn_Hidden = document.getElementById('<%= btn_Hidden.ClientID %>');

        if (txtHidden !== null) {
            txtHidden.innerText = sDate;
        } else{
            alert("Control '<%=txtHidden.ClientID %>' not found.");
        }

        if (btn_Hidden !== null) {
            btn_Hidden.click;
        } else {
            alert("Control '<%= btn_Hidden.ClientID %>' not found.");
        }

    }

The problem I am getting is that the btn_Hidden.click is not firing, but the txtHidden text is being update, but the btn_Hidden.click is not firing.

As you can see from my sample, I have a 'test' in place to see if the btn control is found and it is, as far as I can see.

Troubleshooting steps I have taken are,

  • Removing the txtbox section, no help.
  • Recreating the button on the aspx page, no help.
  • Physically click the button, click event fires.
  • Inserting document.getElementById('<%= btn_Hidden.ClientID %>').click instead of btn_Hidden.click, no help.

Please assist.

Thank you in advance

Rhys

Click is a method not a field in javascript

Simulate a mouse-click use .click() ;

In your code use

  btn_Hidden.click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM