Solved

JavaScript Calculatopr Markup

Posted on 2004-10-20
3
274 Views
Last Modified: 2013-11-19
hello there,
i am trying to add some javascript code in my html but i just cant get it done.
i have 3 products that cost $2.00 dollars each one, and if they want to buy 500 will divide it
by 20%, 8000 divide it by %30 and if they want 12000 for %40, and show the prince thats
all i need to do

here is my html code

<html>
<head>
<title>Calculator Markup</title>
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#000000" width="100%" id="AutoNumber1">
  <tr>
    <td><font face="Verdana" style="font-size: 9pt; font-weight: 700">Product</font></td>
    <td><font face="Verdana" style="font-size: 9pt; font-weight: 700">Quantity</font></td>
    <td><span style="font-weight: 700">
    <font face="Verdana" style="font-size: 9pt">Price per Product $2.00</font></span></td>
  </tr>
  <tr>
    <td>
    <select class="dropdown" style="WIDTH: 99; BACKGROUND-COLOR: #99ccff; height:99" size="1" name="X_Product">
    <option value>Select</option>
    <option value="DF6870">DF6870</option>
    <option value="EF6890">EF6890</option>
    <option value="GF6860">GF6860</option>
    </select></td>
    <td>
    <select class="dropdown" style="WIDTH: 99; BACKGROUND-COLOR: #99ccff; height:99" size="1" name="X_Product">
    <option value>Select</option>
    <option value="500">500</option>
    <option value="8000">8000</option>
    <option value="12000">12000</option>
    </select></td>
    <td>
    <input maxLength="5" name="X_Price" size="20"></td>
  </tr>
  </table>
</body>
</html>
0
Comment
Question by:Xtry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 500 total points
ID: 12360067
Hi xtry-

Something like this?

<html>
<head>
<title>Calculator Markup</title>

<script language="javascript">
<!--
function reCalc(v) {
    var t = document.forms['the_form'].elements['X_Price'];
      var prod = document.forms['the_form'].elements['X_Product'];
      var p = 2;

    if (prod.options[prod.selectedIndex].value != '') {
            switch (v) {
                  case '500':
                        t.value = (p * parseInt(v)) * .8;
                        break;
                  case '8000':
                        t.value = (p * parseInt(v)) * .7;
                        break;
                  case '12000':
                        t.value = (p * parseInt(v)) * .6;
                        break;
                  default:
                        t.value = '';
                        break;
            }
      } else {
        t.value = '';
      }
}
-->
</script>

</head>
<body>
<form name="the_form">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#000000" width="100%" id="AutoNumber1">
  <tr>
    <td><font face="Verdana" style="font-size: 9pt; font-weight: 700">Product</font></td>
    <td><font face="Verdana" style="font-size: 9pt; font-weight: 700">Quantity</font></td>
    <td><span style="font-weight: 700">
    <font face="Verdana" style="font-size: 9pt">Price per Product $2.00</font></span></td>
  </tr>
  <tr>
    <td>
    <select class="dropdown" style="WIDTH: 99; BACKGROUND-COLOR: #99ccff; height:99" size="1" name="X_Product">
    <option value="">Select</option>
    <option value="DF6870">DF6870</option>
    <option value="EF6890">EF6890</option>
    <option value="GF6860">GF6860</option>
    </select></td>
    <td>
    <select class="dropdown" onchange="reCalc(this.value);" style="WIDTH: 99; BACKGROUND-COLOR: #99ccff; height:99" size="1" name="X_Qty">
    <option value="">Select</option>
    <option value="500">500</option>
    <option value="8000">8000</option>
    <option value="12000">12000</option>
    </select></td>
    <td>
    <input maxLength="5" name="X_Price" size="20"></td>
  </tr>
  </table>
  </form>
</body>
</html>
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12360078
Note:  if the price will always be $2, and there will always only be those three options for quantity, there really is no calculation needed.  This can be done much simpler, but I assumed you'd wanted the calculation for an actual JavaScript solution.
0
 

Author Comment

by:Xtry
ID: 12361147
awsome man, thanks a lot
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question