SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2006
    Location
    Cape Town, S.A.
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Javascript in ASP.NET page returning null...

    Hi guys,

    This is my first post here, please be nice . Im working on an asp.net page which has the following textbox:

    <asp:TextBox id="txtQuickComment" class="contact" runat="server" style="width:300px; height:25" Rows="3" MaxLength="250" TextMode="MultiLine"></asp:TextBox>

    I then have an image placeholder defined as follows:

    <img src="../images/smilies/aggressive.gif" alt="upset :-<" id="aggressive" onclick="javascript: addSmileyToTextBox('aggressive')"/>

    When the image is clicked, it calls the addSmileyToTextBox() javascript function, passing the string 'aggressive'. The function is as follows:

    function addSmileyToTextBox(smileyName)
    {
    var smiley = smileyName.toString();
    var txt = document.getElementById("txtQuickComment");
    alert(txt);
    }

    The function above alerts "null". Is this to say the textbox does not exist? Strange. What i wish to do is to modify the function to append a string to the textbox's contents.

    Please help?
    Regards,
    Sithu

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    getElementById will return null if the HTML node was not found, check the source and make sure you really have an element with that id. Maybe .NET adds something to the id? JSF does.

    You are passing a String to the function, so why call a toString method on it?

  3. #3
    SitePoint Member
    Join Date
    Jan 2006
    Location
    Cape Town, S.A.
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks gents...suggestions seem to work!
    Regards,
    Sithu

  4. #4
    Ex-SitePointer silver trophy
    Patrick's Avatar
    Join Date
    Oct 2000
    Location
    Harbinger, NC, U.S.A.
    Posts
    4,126
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    As you already have a thread for this issue, I am going to close this one and redirect you over there. Thanks.

    http://www.sitepoint.com/forums/showthread.php?t=473152


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •