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 3 of 3
  1. #1
    Senior Member
    Join Date
    Apr 2005
    Hatfield, England
    Member #
    I want to keep a running total of the spend so far. When users add certain input boxes the total will be updated and printed to the page.

    This is the theory. The problem is that I have got no where at all.

    <form method="post" name="calcform">
    <div class="form_item">
    	<h3>Add a link to your website for $4</h3>
    	<input type="text" name="website" id="website" onchange="calculate()" value="<?php if (isset($_POST['website'])) { print $_POST['website']; } ?>"/>
    	<p>Be on the homepage and be seen by hundreds of people</p>
    	<input type="checkbox" id="homepage" onchange="calculate()" name="homepage" <?php if (isset($_POST['homepage'])) { print 'CHECKED';} ?>> Home Page Ad (7 Days)
    						<script type="text/javascript">
    							var total = 0;
    							function calculate()
    		<p>Be the first thing users see when they enter your specified category.</p>
    		<select name="duration" category onchange="calculate()">
    			<option value="">None</option>
    			<option value="3" <?php if (isset($_POST['duration']) == '3') { print 'selected="selected"'; } ?> >3 Days</option>
    			<option value="7" <?php if (isset($_POST['duration']) == '7') { print 'selected="selected"'; } ?>>7 Days</option>
    Now what I am trying to do is as follows.
    > If the website input has got someone thing in it then I want to set total variable to 4.
    > If the homepage checkbox is ticked I want to add 20 to the total variable.
    > If the category drop down is set I want I want to multiply 3 by the number of days in the select box.

    I then need to be able to subtract from the total if the check box is unchecked. The category days are set to 0 and the website box is emptied.

    Please.. can someone tell me how I can get the value for each of the 3 form fields. Once I know this I am sure that I can work out the rest myself.


  3. #2
    Join Date
    Apr 2007
    Member #
    Without really looking at your form, the general answer to your question is to use getElementById("formfieldid")

    So if you have a form like
    <input type="text" name="somenumber" id="somenumber" onchange="calculate();"/>
    <input type="text" name="anothernumber" id="anothernumber" onchange="calculate();"/>
    <input type="text" name="total" id="total" />

    <script type="text/javascript">
    function calculate()
    var number1 = document.getElementById("somenumber").value;
    var number2 = document.getElementById("anothernumber").value;
    var number3 = number1 + number2;

    document.getElementById("total").value = number3;

  4. #3
    Senior Member Shani's Avatar
    Join Date
    Nov 2004
    Member #
    Still looking for help on this?

    I can go into more detail if you need, but I would say your best bet is to write one method that does all the math. That way you don't have to add or subtract, all you have to do when the parameters change, is redo the math.

    I have an eye for detail like you'd never believe.

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
All times are GMT -6. The time now is 12:07 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: