View Full Version : Send Javascript Output to a label instead of text box

07-13-2007, 05:58 AM
I've been searching for about 45 minutes and can't find exactly what I am looking for. I am using this Update Order Form (http://javascript.internet.com/forms/update-order-form-no-page-refresh.html) script that should work for me. The only problem I have is that it needs to update the price out side of a text box. It doesn't matter if it is in a label or just printed to the screen as long as I can do some formatting to it. Thanks for the help.

07-13-2007, 06:16 AM
A think a span or a div would be the more appropriate element to use in this case as a label is not really mean for this type of thing. Use this for the initForm function

// This function initialzes all the form elements to default values.
function InitForm() {
// Reset values on form.

// Set all checkboxes and radio buttons on form to unchecked.
for (i=0; i < document.selectionForm.elements.length; i++) {
if (document.selectionForm.elements[i].type == 'checkbox' | document.selectionForm.elements[i].type == 'radio') {
document.selectionForm.elements[i].checked = false;
Then use this for the html.

<div align="center">
<form method="POST" name="selectionForm">
<b>Pizza Order</b><br>
Small $10.00
<input type="checkbox" name="Steak" value="10.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);">
Medium $12.00
<input type="checkbox" name="Chicken" value="12.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);">
Large $15.00
<input type="checkbox" name="Sushi" value="15.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);">
<b>Extra Toppings (only one selection allowed):</b> <br>
<input type="radio" name="Sauce" value="0.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);"> None
<input name="Sauce" type="radio" value="1.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);"> Extra Cheese $1.00
<input type="radio" name="Sauce" value="2.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);"> Vegetarian $2.00
<input type="radio" name="Sauce" value="3.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);"> Meat $3.00
<input type="hidden" name="calculatedTotal" value="0">
<input type="hidden" name="previouslySelectedRadioButton" value="0">
<strong>Your total is:</strong>
<span id="total">&nbsp;</span>

07-13-2007, 06:37 AM
Aerospace, your awesome. :thumbsup: Exactly what I wanted. Can't believe it was that simple. Thanks, I would never have figured that out on my own.

07-13-2007, 06:41 AM
BTW, if anyone is wondering how it looks http://drakeleto.com/priceupdate/test.php

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum