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
    Nov 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding values from a drop down list

    Hi,
    I was wondering if anyone could help me? I am making an order form and am trying to calculate the cost. I have two drop down boxes which each have two options. The first is "8:30 - 4:30" & "8:00 - 6:00" now the cost for each are £17.50 and £20.00. I want to be able to automatically calculate the cost when the user selects each day and time.

    example
    Day 1 [8:00 - 6:00] Day 2 [8:00 - 6:00]
    total (£40.00)

    here is the code for the form i have at present:

    <form name="form1" method="post" action="">
    Day 1
    <select name="day1" id="day1">
    <option>8:30 - 4:30</option>
    <option>8:00 - 6:00</option>
    </select>
    Day 2
    <select name="day2" id="day2">
    <option>8:30 - 4:30</option>
    <option>8:00 - 6:00</option>
    </select>
    <br>
    <br>
    Total:
    <input name="total" type="text" id="total" size="6">
    </form>

    Thank you for your help, I am just starting out with javascript and can't find anything in books or on the web.

    Thanks Again,
    Andy

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>47355</title>
    	</head>
    	<body>
    		<form name="form1" method="post" action="">
    			<fieldset>
    				<label for="day1">Day 1</label>
    				<select id="day1" name="day1" onchange="update_total()">
    					<option value="17.50">8:30 - 4:30</option>
    					<option value="20.00">8:00 - 6:00</option>
    				</select>
    				<label for="day2">Day 2</label>
    				<select id="day2" name="day2" onchange="update_total()">
    					<option value="17.50">8:30 - 4:30</option>
    					<option value="20.00">8:00 - 6:00</option>
    				</select>
    				<label for="total">Total</label>
    				<input id="total" name="total" type="text" size="6">
    			</fieldset>
    		</form>
    	</body>
    	<script type="text/javascript">
    		function update_total()
    		{
    			document.getElementById("total").value = parseFloat(document.getElementById("day1").value) + parseFloat(document.getElementById("day2").value);
    		}
    
    		update_total();
    	</script>
    </html>
    Gecko Dom Reference

  • #3
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    Thank You so much hemebond , that is exactly what I wanted. Brilliant !
    Cheers.

    Really sorry to be a pain, but is there any way of being able to have £35.00 instead of 35. Thank you for all your help you people are brilliant!
    Last edited by arc2002; 11-11-2004 at 09:40 PM.

  • #4
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    			document.getElementById("total").value = Number(Number(document.getElementById("day1").value).toFixed(2) + Number(document.getElementById("day2").value)).toFixed(2);


  •  

    Posting Permissions

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