Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing text on a form button when clicked...

Status
Not open for further replies.

pjfarr

Technical User
Dec 1, 2001
45
CA
How do I get the text on a form button to change each time it's pressed? Ideally, I need 4 alternating labels.

Initially, it displays Text #1
When pressed the first time, it changes to Text #2.
The second press changes it to Text #3, and so on.

As the button launches a new graphic with each press, I'd like the text on the button to cue the user for the next press.

Thanks...
~P.J.F.
 
Here you go:

Code:
<html>
<head>
	<script type="text/javascript">
		var buttonTextNum = 0;
		var newButtonText = ['Initial text', 'Next text', 'Even more text', 'Yet more text', 'Aren\'t we done here yet?'];

		function setText() {
			buttonTextNum++;
			if (buttonTextNum == newButtonText.length) buttonTextNum = 0;
			document.getElementById('myButton').value = newButtonText[buttonTextNum];
		}
	</script>
</head>

<body>
	<input type="button" id="myButton" onclick="setText();" value="Initial text" />
</body>
</html>

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
That was it!
Thanks X 1,000,000, Dan.

~P.J.F.
 
By the way, big LOL at "'Aren\'t we done here yet?'"

~P.J.F.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top