...

View Full Version : change <p> contents



JoWiGo
08-19-2005, 08:22 PM
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?

nikkiH
08-19-2005, 08:24 PM
document.getElementById("idname").innerHTML="whatever"

martin_narg
08-19-2005, 08:29 PM
This should give you a good idea of what to do:


<!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

JoWiGo
08-19-2005, 09:36 PM
Can you tell me why the following code isn't working?


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

martin_narg
08-19-2005, 10:02 PM
Is this more like what you are trying to do?


<!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


if(a == b) {
...
} else if(a == c) {
...
}

rather than


if(a = b) {
...
} elseif(a = c) {
...
}

Please note also that JavaScript is a case-sensitive language.

Hope this helps

m_n



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum