...

View Full Version : innerHTML and ChangeText of multiple values



cptfishstick
01-12-2009, 02:03 AM
I need for the text to change on my page. I want it to change to 'value a' when 'button a' is pressed, and 'value b' when 'button b' is pressed. All the tutorials online only solve for a single value change with a single button. I am new to java, so please advise. The example below has the second button I want, it just doesn't change the value. Only the first button does. Thanks for your time.

P.S. I am new to java, so I'm not sure if this actually qualifies as an AJAX question, or just a general HTML question.


<html>
<head>
<script language="JavaScript" type = "text/javascript">
function ChangeText()
{
var curtextval = document.getElementById("ptext");
curtextval.innerHTML = "Text is now A"
}
</script>
</head>
<body>
<form>
<p id="ptext">This is the original text</p>
<input type="button" value="Change Text to A" onClick="ChangeText()"></p>
<input type="button" value="Change Text to B" onClick="ChangeText()"></p>

</form>
</body>
</html>

abduraooft
01-12-2009, 08:25 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type = "text/javascript">
function ChangeText(str)
{
var curtextval = document.getElementById("ptext");
curtextval.innerHTML = "Text is now "+str;
}
</script>
</head>
<body>
<form>
<p id="ptext">This is the original text</p>
<input type="button" value="Change Text to A" onClick="ChangeText('A')"></p>
<input type="button" value="Change Text to B" onClick="ChangeText('B')"></p>

</form>
</body>
</html>


P.S. I am new to java, so I'm not sure if this actually qualifies as an AJAX question, or just a general HTML question.
Java (http://en.wikipedia.org/wiki/Java_(programming_language)) and javascript (http://en.wikipedia.org/wiki/JavaScript) are not the same. And surely this is not an AJAX (http://en.wikipedia.org/wiki/AJAX) question.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum