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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    114
    Thanks
    4
    Thanked 3 Times in 3 Posts

    change <p> contents

    Is there anyway to do this? As in,
    document.helpparagraph="This is the new text for a paragraph with an id of helpparagraph"[/CODE]

    Is there an attribute that I dont know of here?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    document.getElementById("idname").innerHTML="whatever"

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    This should give you a good idea of what to do:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function changeText(id, str) {
    	document.getElementById(id).innerHTML = str;
    }
    </script>
    </head>
    
    <body>
    <p id="txt1">Hello world</p>
    <p id="txt2">Hello world again</p>
    <form name="frm">
    <input type="button" name="btn" value="click me" onclick="changeText('txt1', 'New content')">
    &nbsp;&nbsp;
    <input type="button" name="btn" value="click me" onclick="changeText('txt2', 'More new content')">
    </form>
    </body>
    </html>
    Hope this helps

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    114
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Can you tell me why the following code isn't working?

    Code:
    <head>
    <script>
    <!--
    function gethelp(id,help){
      if (id="g"){
      if (help="name"){
       h = "this is some text";
      }elseif(help="othername"){
       h = "this is some other text";
     }
     }elseif(id="a"){
      if (help="x"){
       h="Another type";
      }
     }
     document.helpf.getElementById(help).innerHTML = h;
    }
    -->
    </script>
    </head>
    <body>
    <form id="helpf"><fieldset id="help"><label>Help Box</label>This is the help box.  To recieve help in this area, just click on the [?] links throughout the page.</fieldset></form>
    <a href="#" "onclick="gethelp('a','x');">[?]</a>
    </body>
    </html>

  • #5
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Is this more like what you are trying to do?
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function gethelp(id, opt) {
    	switch(opt) {
    		case 1:
    			var str = "This is some text";
    		break;
    		
    		case 2:
    			var str = "This is some more text";
    		break;
    		
    		case 3:
    			var str = "This is yet more text";
    		break;
    		
    		// keep adding more helps here
    		/* e.g 
    		case 4:
    			var str = "blah blah blah";
    		break;
    		*/
    	}
    	document.getElementById(id).innerHTML = str;
    }
    </script>
    </head>
    
    <body>
    <form name="helpf">
    	<fieldset id="help">
    	<label>Help Box</label>
    	This is the help box.  To recieve help in this area, just click on the [?] links throughout the page.
    	</fieldset>
    </form>
    <a href="#" onclick="gethelp('pHelp',1); return false;">[?] help 1</a><br>
    <a href="#" onclick="gethelp('pHelp',2); return false;">[?] help 2</a><br>
    <a href="#" onclick="gethelp('pHelp',3); return false;">[?] help 3</a><br>
    <p id="pHelp"></p>
    </body>
    </html>
    FYI:
    This is correct javascript syntax is
    Code:
    if(a == b) {
      ...
    } else if(a == c) {
      ...
    }
    rather than
    Code:
    if(a = b) {
      ...
    } elseif(a = c) {
      ...
    }
    Please note also that JavaScript is a case-sensitive language.

    Hope this helps

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper


  •  

    Posting Permissions

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