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

5
  • 1
    catb.org/~esr/faqs/smart-questions.html Commented Jun 24, 2009 at 5: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? Commented Jun 24, 2009 at 5:25
  • Make sure you have a button with the ID of 'ibtnSubmit' and that it's spelled correctly Commented Jun 24, 2009 at 5: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)... Commented Jun 24, 2009 at 5: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 :) Commented Jun 24, 2009 at 5:48

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.