Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    displaying text in span

    hi all,

    Im trying to set the text inside a span when i click a button ..

    the span is
    <spand id=sText></span>
    and the button just triggers onclick call to 'building' as below...
    function building() {
    sText.value="test info";
    }
    but nothing happens when I click...

    have I missed something? ny pointers be very much apperciated.

    cheers very much
    Sir P

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You have a typo in your opening span tag

    <spand id=sText></span>

    and you should be referencing as

    document.getElementById("sText").innerHTML="test info";
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    If its just text you are trying to set then I would do something like this instead
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function setText(where,what)
    {
    	document.getElementById(where).firstChild.nodeValue = what;
    }	
    </script>
    </head>
    <body>
    <div>
    	<input type="button" onclick="setText('sText','test info 1');" value="Set Text 1"><br>
    	<input type="button" onclick="setText('sText2','test info 2');" value="Set Text 2"><br>
    	<input type="button" onclick="setText('sText3','test info 3');" value="Set Text 3"><br>
    	<!--something needs to be in the span for the function to work-->
    	<span id="sText">&nbsp;</span><br>
    	<span id="sText2">&nbsp;</span><br>
    	<span id="sText3">&nbsp;</span></div>
    </body>
    </html>
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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