471,603 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,603 software developers and data experts.

HTML dynamic calculation

I have following code in HTML file:

<input type="text" name="Quantity" size="10" maxlength="10">

<input type="text" name="Unitprice" size="10" maxlength="10">

<input type="text" name="Totalprice" size="10" maxlength="10">

My question is that, I have to show the calculated value in the field "Totalprice" dynamically with the changed value of "Unitprice" as well as "Quantity" in the same page where "Totalprice = Quantity * Unitprice".

can someone help to do this???

Dec 2 '07 #1
2 1996
7,435 Expert 4TB
html/css cannot do this. You need a programming language.
Dec 2 '07 #2
Without the whole code I have no idea what you are trying to do. It looks like you are trying to create a form.If you wanted the broswer to calculate the total before the form is submited you would need to use javascript(client side code). No good at javascript so i'll leave that for someone else.

If you want a user to input the "quantity" and "unit price" and submit it to the server before showing the result (recommended approach), you need to use a server language such as PHP, ASP, Cold Fusion etc.
If you haven't considered using these before be prepared to do a lot of reading.

You would most likely need to pull the Unit price from a database or code it into the page. Not sure why you would want an input field for this.

Anyway back the original question-
PHP example code would something like this.

$quantity = 5;
$unit_price = 10;
$total_price = ($quantity * $unit_price) ;
echo $total_price;

output of the above code would be-

this code by itself is basically useless. If you are serious about creating dynamic pages start learning PHP or ASP
Dec 14 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by murrayatuptowngallery | last post: by
2 posts views Thread by justplain.kzn | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.