PDA

View Full Version : Alternating text value



mhodgson
11-22-2007, 04:44 PM
How can I make a piece of text alternate between two values.

For example: a default value (in a text box?) is 'even' when the page loads but when I click a button it changes to 'odd'. If I click the button again it returns to 'even' and so on, alternating between odd and even.

jscheuer1
11-22-2007, 05:11 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<form action="#">
<div>
<input name="even_odd" type="text" readonly value="even"><br>
<input type="button"
onclick="var e=this.form.elements['even_odd'];
e.value=e.value=='odd'?'even':'odd';"
value="Toggle">
</div>
</form>
</body>
</html>

mhodgson
11-23-2007, 02:07 PM
works great thanks, even managed to alter it for another page that does not use forms.

MANY THANKS