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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display contents of select box

Status
Not open for further replies.

jgd12345

Technical User
Apr 22, 2003
124
GB
Hi, I've got a problem I expect you guys'll solve in 5 seconds but has been troubling all day.

Right here it is. I've got the following code:

<script language="JavaScript">
function updateCurrency() {
var totamount = document.newItem.payment.value
writeLayer("totalAmount", totamount);
}
</script>

<form name="newItem">
<select name="payment" onchange="javascript:updateCurrency()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

<DIV id=totalAmount><script>document.write(totamount)</script></div>
</form>

Basically what I want todo is display the contents of the select box just as plain text next to it. I'd be greatful if anyone could help. Thanks
 

Try something like this:

Code:
<html>
<head>
	<script type="text/javascript">
	<!--
		function updateCurrency(selObj) {
			document.getElementById('totalAmount').innerHTML = selObj.options[selObj.selectedIndex].value;
		}
	//-->
	</script>
</head>

<body>
	<form name="newItem">
		<select name="payment" onchange="updateCurrency(this);">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
		</select>
		<div id="totalAmount"></div>
	</form>
</body>
</html>

Hope this helps,
Dan
 
Hi worked a treat one prob though it goes onto a new line and the text after that aswell. I've uploaded the file so you can see
I strictly don't want todo this and be greatful if you could show me how to resolve it. Thanks
 

Change this:

Code:
document.getElementById('totalAmount').innerHTML = selObj.options[selObj.selectedIndex].value;

for this:

Code:
document.getElementById('totalAmount').innerHTML = selObj.options[selObj.selectedIndex].value + ' points';

and remove the word "Points" from the HTML.

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top