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

Nosredna
  • 83,000
  • 15
  • 95
  • 122
  • 1
    http://catb.org/~esr/faqs/smart-questions.html – sqram Jun 24 '09 at 05:21
  • 1
    Your code and error message weren't showing up. I marked them as code. You might want to reformat a bit so the lines aren't so long. Is that how it looks in your code? – Nosredna Jun 24 '09 at 05:25
  • Make sure you have a button with the ID of 'ibtnSubmit' and that it's spelled correctly – sqram Jun 24 '09 at 05:27
  • If you can provide a larger sample of the page - it will help us help you (especially the part where the 'ibtnSubmit' is added)... – Dror Jun 24 '09 at 05:35
  • I understand that you're new here, but you need to take a look at the FAQ to learn more about the prober method to write a question :) – Ahmed Jun 24 '09 at 05:48

2 Answers2

4

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
  • 21,302
  • 14
  • 69
  • 94
2

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.

John Ferguson
  • 786
  • 1
  • 7
  • 21
rahul
  • 184,426
  • 49
  • 232
  • 263