Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Send Javascript Output to a label instead of text box

    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 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.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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
    Code:
    // This function initialzes all the form elements to default values.
    function InitForm() {
      // Reset values on form.
      document.getElementById('total').firstChild.data='$0';
      document.selectionForm.calculatedTotal.value=0;
      document.selectionForm.previouslySelectedRadioButton.value=0;
    
      // 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.
    Code:
    <div align="center">
    <table><tr><td>
      <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);">
        <br><br>
        <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
        <br>
          <input name="Sauce" type="radio"  value="1.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);"> Extra Cheese $1.00
        <br>
          <input type="radio" name="Sauce" value="2.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);"> Vegetarian $2.00
        <br>
          <input type="radio" name="Sauce" value="3.00" onclick="document.getElementById('total').firstChild.data=calculateTotal(this);"> Meat $3.00
        <br>
        <br>
        <input type="hidden" name="calculatedTotal" value="0">
        <input type="hidden" name="previouslySelectedRadioButton" value="0">
        <strong>Your total is:</strong>
        <span id="total">&nbsp;</span>
      </form>
    </td></tr></table>
    </div>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Aerospace, your awesome. Exactly what I wanted. Can't believe it was that simple. Thanks, I would never have figured that out on my own.

  • #4
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    BTW, if anyone is wondering how it looks http://drakeleto.com/priceupdate/test.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •