When you create a form in HTML for calculating something, how do you make the output show on the same screen?I want to calculate blood alcohol with three input area in a form (number of drinks, number of hours, and weight) which then figures out the blood level of the person. I don't know how to make the output show.
Answer by jkurrle
HTML does not have the capability to do this. You need a scripting language like Javascript, Perl, or PHP to do it.
Answer by fjpoblam
Probably the easiest way would be to write a PHP script on the server which would read the input fields entered on the form, then re-display the form with the results entered and the computation results displayed.
Answer by blessed_thang
You write it as javascript. The javascript has a function that collects all the form box contents, does the math and puts the result into another document object of your design -- such as a textarea, a div. Several approaches to do this. Suppose you have 3 entry boxes on a form named Q1 ... Q3
function validate_form() {
a = document.form.Q1.value;
b = document.form.Q2.value;
c = document.form.Q3.value;
total = a + b + c;
alert ("Total = " + total);
}
on the html page you have a button. The button has a function call like this:
onclick="validate_form()">
you can get snippets of code, tutorials at the link below
Orignal From: When you create a form in HTML for calculating something, how do you make the output show on the same screen?
No comments:
Post a Comment