Reputation:
<asp:TextBox ID="txtOriginalNo" runat="server" onkeyup="javascript:if (event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('ibtnSubmit').click();}};"
onKeyDown="return AlphaNumeric(event)" TabIndex="1"></asp:TextBox>
i am getting runtime error Microsoft JScript runtime error: 'document.getElementById(...)' is null or not an object
<asp:TextBox ID="txtOriginalNo" runat="server" **onkeyup="javascript:if (event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('ibtnSubmit').click();}};"**
onKeyDown="return AlphaNumeric(event)" TabIndex="1"></asp:TextBox>
i am using master page.
can anybody help me
Upvotes: 0
Views: 435
Reputation: 187110
I think the id of the button will be prepended with a unique id[prepended with some contentplaceholderid]
Eg: If you give the button id as btnSubmit then it will be generated as
ctl00_ContentPlaceHolder1_btnSubmit
where id of the contentplaceholder is 'ContentPlaceHolder1'
Edit:
var placeHolderID = '<%=ContentPlaceHolder1.ClientID%>';
var buttonToBeClicked = document.getElementById ( placeHolderID + "_" + "ibtnSubmit" );
buttonToBeClicked.click();
Hope this solves your problem.
Upvotes: 2
Reputation: 21575
This happened because document.getElementById returned null. In other words, it did not find the ID you were looking for.
You can prevent it my making sure the ID exists in the document, or do a check comparing the result of getElementById to null.
Upvotes: 4