javascript within asp.net framework, document.getElementbyId error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpmel
    New Member
    • Oct 2007
    • 69

    javascript within asp.net framework, document.getElementbyId error

    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.

    Code:
    <script type="text/javascript" >
            function changemsg(lbl){
                document.getElementById(lbl).innerHTML=" ";
            }
    </script>
    on the page load method of my page, i call the function as follows
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                manuTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_manuLabel');");
                wcTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_wcLabel');");
                vmTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_descLabel');");
               
            }
        }
    i am using master pages, that is why i am saying 'ctl00_ContentP laceHolder1_des cLabel' 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.getEl ementById(...)' 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?
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    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

    Comment

    • phpmel
      New Member
      • Oct 2007
      • 69

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

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        no problem ... ;) post back when you have more problems with it ...

        kind regards

        Comment

        Working...