Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Mar 2008
    Posts
    7
    Member #
    16541
    Hi Everyone,
    I am fairly new at trying to javascript, so be gentle. I have a client who wants a form with calculating fields. The price field will change according to the options they have made in the fields above. Here is the following form code:

    Code:
      <form action="" method="post" enctype="multipart/form-data" name="orderform" id="orderform">
                      <table width="100%" border="0" cellpadding="0" cellspacing="5" class="style8">
                        <tr>
                          <td>Quantity</td>
                          <td><select name="quantity" class="style8" id="quantity">
                            <option value="1000">1000</option>
                            <option value="5000">5000</option>
                            <option value="10000">10000</option>
                            <option value="15000">15000</option>
                          </select>                    </td>
                        </tr>
                        <tr>
                          <td>Coating</td>
                          <td><input name="coating" type="radio" value="uv" />
                            uv (glossy) 
                              <input name="coating" type="radio" value="aqueous" />
                              aqueous (non-glossy) </td>
                        </tr>
                        <tr>
                          <td>Corners</td>
                          <td><select name="corners" class="style8" id="corners">
                            <option value="normal">normal</option>
                            <option value="rounded">rounded</option>
                          </select>                    </td>
                        </tr>
                        <tr>
                          <td>Design</td>
                          <td><input name="design" type="checkbox" id="design" value="design" />
                            yes</td>
                        </tr>
                        <tr>
                          <td>File Front   </td>
                          <td><input name="filefront" type="file" class="style8" id="filefront" /></td>
                        </tr>
                        <tr>
                          <td>File Back  </td>
                          <td><input name="fileback" type="file" class="style8" id="fileback" /></td>
                        </tr>
                        <tr>
                          <td>Job Title </td>
                          <td><input name="jobtitle" type="text" class="style8" id="jobtitle" size="50" /></td>
                        </tr>
                        <tr>
                          <td><strong>Price</strong></td>
                          <td><input name="price" type="text" class="style8" id="price" /></td>
                        </tr>
                      </table>
      </form>
    They would like the base price to be $90 for 1000. Here are the other prices, respectively: 5k for $175, 10k for $350 and 15k for $525. If they choose rounded corners, then the price increases by $25 (normal is no additional cost). If they choose design, it is an extra $75.

    Can someone please help me write this please? I have been trying to review codes, and I am learning as I go. Thank you very much for your anticipated assistance.

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    The formulas can be coded however you like. The way to do this would be to register either an `onblur' or an `onchange' event on each input. These would call a function that redoes the calculation and displays the final price.

    Note that the above setup allows the user to modify the price, though, so relying on its being correct once they submit the form is a bad idea.

  4. #3
    Junior Member
    Join Date
    Mar 2008
    Posts
    7
    Member #
    16541
    Hi Shadowfiend,
    Since you said that the price field could be changed, which way do you recommend approaching this? Since I am new to JS, I am not sure how to write a script using the onchange events.

  5. #4
    Junior Member womble's Avatar
    Join Date
    Mar 2008
    Posts
    15
    Member #
    16580
    you need to write a js function which changes the value of the price input - call this function using the onchange event of the select dropdown - if that all sounds confusing take a look at w3schools.com javascript section


Remove Ads

Posting Permissions

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

Search tags for this page

ajax calculating form fields

Click on a term to search for related topics.
All times are GMT -6. The time now is 05:47 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com