The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> IF Calculations based on dropdown list
coryjacques
post Dec 13 2018, 02:10 PM
Post #1





Group: Members
Posts: 2
Joined: 13-December 18
Member No.: 26,771



Hello!

This is probably a little bit HTML and a lot a bit... something else (I'm new to HTML/Java/etc).

I have a code (below) to set up a two-question form. I'm looking to calculate excel-style based on the values a user selects. Here's the code:

CODE
<!DOCTYPE html>
<html>
<head>
    <title>How much will your plan cost?</title>
</head>
<body>
<table>
<tr></tr>
    <td><div align="Center"><h5>How much will your plan cost?</h5></td></tr>
    <Form action="processingscript.php" method="post">
    <tr>
    <td><p>How old are you?<select>
            <Option>Under 24</Option>
            <option>25-29</option>
            <option>30-34</option>
            <Option>35-39</option>
            <Option>40-44</option>
            <Option>45-49</option>
            <Option>50-54</option>
            <Option>55-59</option>
            <Option>60-64</option>
            <Option>65-69</option>

            </select></P></td></tr>
    <tr><td><p>How much of a benefit amount are you looking for?<Select>
        <Option> $10000</option>
<Option> 20000</option>
<Option> 30000</option>
<Option> 40000</option>
<Option> 50000</option>
<Option> 60000</option>
<Option> 70000</option>
<Option> 80000</option>
<Option> 90000</option>
<Option> 100000</option>
<Option> 110000</option>
<Option> 120000</option>
<Option> 130000</option>
<Option> 140000</option>
<Option> 150000</option>
<Option> 160000</option>
<Option> 170000</option>
<Option> 180000</option>
<Option> 190000</option>
<Option> 200000</option>
<Option> 210000</option>
<Option> 220000</option>
<Option> 230000</option>
<Option> 240000</option>
<Option> 250000</option>
<Option> 260000</option>
<Option> 270000</option>
<Option> 280000</option>
<Option> 290000</option>
<Option> 300000</option>
<Option> 310000</option>
<Option> 320000</option>
<Option> 330000</option>
<Option> 340000</option>
<Option> 350000</option>
</Select><br>
<tr><td><div align="center"><input type="submit" value="Calculate!"></div></tr></td>
    </Form>
</table>
</center>
</body>
</html>


Here's the table I'm trying to pull from - I'm essentially looking for something along the lines of "If the first box says 25-29, .04 will be multiplied by the value in the second box" for example.


Age Band | Multiple
<24 | $0.04
25-29 | $0.04
30-34 | $0.05
35-39 | $0.08
40-44 | $0.12
45-49 | $0.21
50-54 | $0.36
55-59 | $0.59
60-64 | $0.79
65-69 | $1.25


If it helps, in excel this would be something along the lines of (if box 1 is a1 and box 2 is a2): =if(or(a1="<24",a1="25-29"),a2*.04,if(a1="30-34",a2*.05, .....etc.

Any tips?

This post has been edited by coryjacques: Dec 13 2018, 02:17 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
coryjacques
post Dec 19 2018, 02:10 PM
Post #2





Group: Members
Posts: 2
Joined: 13-December 18
Member No.: 26,771



Thank you! I know absolutely nothing about PHP, but I'll look up some lessons and see if I can figure it out!

Our server isn't doing anything with the data once submitted - this is actually meant to make up for a few shortcomings in our new HRIS; it's no more than a calculator and reference.

This post has been edited by coryjacques: Dec 19 2018, 02:12 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 19 2018, 03:02 PM
Post #3


.
********

Group: WDG Moderators
Posts: 9,650
Joined: 10-August 06
Member No.: 7



QUOTE(coryjacques @ Dec 19 2018, 08:10 PM) *

Our server isn't doing anything with the data once submitted - this is actually meant to make up for a few shortcomings in our new HRIS; it's no more than a calculator and reference.

In that case you might write it with javascript as well (and you don't need to submit any form, you just need the SELECT menus and a button for calculating). For example:

CODE
<script type="text/javascript">
function calculate_benefits()
{
    var age=document.getElementById('age').value;
    var benefit=document.getElementById('benefit').value;
    document.getElementById('result').value=age*benefit;
}
</script>

<select id="age">
<Option value="0.04">Under 24</Option>
<option value="0.04">25-29</option>
<option value="0.05">30-34</option>
</select>

<Select id="benefit">
<Option value="10000">$10000</option>
<Option value="20000">$20000</option>
<Option value="30000">$30000</option>
</select>

<p><input type="button" onclick="calculate_benefits();" value="Calculate"> <input type="text" id="result" value=""></p>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th April 2024 - 08:29 AM