By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

javascript within framework, document.getElementbyId error

P: 69
hi guys,

here is my problem. i have a js function called changemsg that takes a label in an aspx page and sets its text to blank.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" >
  2.         function changemsg(lbl){
  3.             document.getElementById(lbl).innerHTML=" ";
  4.         }
  5. </script>
on the page load method of my page, i call the function as follows
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         if (!IsPostBack)
  4.         {
  5.             manuTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_manuLabel');");
  6.             wcTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_wcLabel');");
  7.             vmTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_descLabel');");
  9.         }
  10.     }
i am using master pages, that is why i am saying 'ctl00_ContentPlaceHolder1_descLabel' instead of plain descLabel etc.
Also, it is worth noting that i am calling the same function with different labels.

my problem is that if i Enable script Debugging in internet explorer, when the page loads, the message is
"document.getElementById(...)' is null or not an object"

even if i disable script Debugging in internet explorer, the status bar would say "done but with errors" and that is the error behind it

how can i fix the problem
is my code correct?
Jun 3 '08 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 5,390
please have a look at or post the generated html-code ... and check whether the ids are correct or not ... or give a link to a testpage.

kind regards
Jun 3 '08 #2

P: 69
thank you for you suggestion,

i did view the generated source code and what i discovered was that there was no code for the labels since i had initially set them to be NOT visible, so when the page is loaded it was causing the error. i set the labels visible=true and i believe it is working now.

thank you so much. i am going to play around with it a little bit and if anything else occurs, i will post back

thank you again
Jun 3 '08 #3

Expert Mod 5K+
P: 5,390
no problem ... ;) post back when you have more problems with it ...

kind regards
Jun 3 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.