tags:

views:

111

answers:

3
<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

+3  A: 

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.

MiffTheFox
+1  A: 

I think the id of the button will be appended with a unique id[appended 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.

rahul
ya you are right...do u know the solution for this?
Please do check the edit.
rahul